GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b130b6...8a2f54 )
by gyeong-won
07:36
created
libs/PEAR.1.9.5/HTTP/Request2/CookieJar.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -425,7 +425,7 @@
 block discarded – undo
425 425
      *
426 426
      * @param string $domain domain name
427 427
      *
428
-     * @return string|bool   registered domain, will return false if $domain is
428
+     * @return false|string   registered domain, will return false if $domain is
429 429
      *                       either invalid or a TLD itself
430 430
      */
431 431
     public static function getRegisteredDomain($domain)
Please login to merge, or discard this patch.
Indentation   +457 added lines, -457 removed lines patch added patch discarded remove patch
@@ -33,462 +33,462 @@
 block discarded – undo
33 33
  */
34 34
 class HTTP_Request2_CookieJar implements Serializable
35 35
 {
36
-    /**
37
-     * Array of stored cookies
38
-     *
39
-     * The array is indexed by domain, path and cookie name
40
-     *   .example.com
41
-     *     /
42
-     *       some_cookie => cookie data
43
-     *     /subdir
44
-     *       other_cookie => cookie data
45
-     *   .example.org
46
-     *     ...
47
-     *
48
-     * @var array
49
-     */
50
-    protected $cookies = array();
51
-
52
-    /**
53
-     * Whether session cookies should be serialized when serializing the jar
54
-     * @var bool
55
-     */
56
-    protected $serializeSession = false;
57
-
58
-    /**
59
-     * Whether Public Suffix List should be used for domain matching
60
-     * @var bool
61
-     */
62
-    protected $useList = true;
63
-
64
-    /**
65
-     * Array with Public Suffix List data
66
-     * @var  array
67
-     * @link http://publicsuffix.org/
68
-     */
69
-    protected static $psl = array();
70
-
71
-    /**
72
-     * Class constructor, sets various options
73
-     *
74
-     * @param bool $serializeSessionCookies Controls serializing session cookies,
75
-     *                                      see {@link serializeSessionCookies()}
76
-     * @param bool $usePublicSuffixList     Controls using Public Suffix List,
77
-     *                                      see {@link usePublicSuffixList()}
78
-     */
79
-    public function __construct(
80
-        $serializeSessionCookies = false, $usePublicSuffixList = true
81
-    ) {
82
-        $this->serializeSessionCookies($serializeSessionCookies);
83
-        $this->usePublicSuffixList($usePublicSuffixList);
84
-    }
85
-
86
-    /**
87
-     * Returns current time formatted in ISO-8601 at UTC timezone
88
-     *
89
-     * @return string
90
-     */
91
-    protected function now()
92
-    {
93
-        $dt = new DateTime();
94
-        $dt->setTimezone(new DateTimeZone('UTC'));
95
-        return $dt->format(DateTime::ISO8601);
96
-    }
97
-
98
-    /**
99
-     * Checks cookie array for correctness, possibly updating its 'domain', 'path' and 'expires' fields
100
-     *
101
-     * The checks are as follows:
102
-     *   - cookie array should contain 'name' and 'value' fields;
103
-     *   - name and value should not contain disallowed symbols;
104
-     *   - 'expires' should be either empty parseable by DateTime;
105
-     *   - 'domain' and 'path' should be either not empty or an URL where
106
-     *     cookie was set should be provided.
107
-     *   - if $setter is provided, then document at that URL should be allowed
108
-     *     to set a cookie for that 'domain'. If $setter is not provided,
109
-     *     then no domain checks will be made.
110
-     *
111
-     * 'expires' field will be converted to ISO8601 format from COOKIE format,
112
-     * 'domain' and 'path' will be set from setter URL if empty.
113
-     *
114
-     * @param array    $cookie cookie data, as returned by
115
-     *                         {@link HTTP_Request2_Response::getCookies()}
116
-     * @param Net_URL2 $setter URL of the document that sent Set-Cookie header
117
-     *
118
-     * @return   array    Updated cookie array
119
-     * @throws   HTTP_Request2_LogicException
120
-     * @throws   HTTP_Request2_MessageException
121
-     */
122
-    protected function checkAndUpdateFields(array $cookie, Net_URL2 $setter = null)
123
-    {
124
-        if ($missing = array_diff(array('name', 'value'), array_keys($cookie))) {
125
-            throw new HTTP_Request2_LogicException(
126
-                "Cookie array should contain 'name' and 'value' fields",
127
-                HTTP_Request2_Exception::MISSING_VALUE
128
-            );
129
-        }
130
-        if (preg_match(HTTP_Request2::REGEXP_INVALID_COOKIE, $cookie['name'])) {
131
-            throw new HTTP_Request2_LogicException(
132
-                "Invalid cookie name: '{$cookie['name']}'",
133
-                HTTP_Request2_Exception::INVALID_ARGUMENT
134
-            );
135
-        }
136
-        if (preg_match(HTTP_Request2::REGEXP_INVALID_COOKIE, $cookie['value'])) {
137
-            throw new HTTP_Request2_LogicException(
138
-                "Invalid cookie value: '{$cookie['value']}'",
139
-                HTTP_Request2_Exception::INVALID_ARGUMENT
140
-            );
141
-        }
142
-        $cookie += array('domain' => '', 'path' => '', 'expires' => null, 'secure' => false);
143
-
144
-        // Need ISO-8601 date @ UTC timezone
145
-        if (!empty($cookie['expires'])
146
-            && !preg_match('/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+0000$/', $cookie['expires'])
147
-        ) {
148
-            try {
149
-                $dt = new DateTime($cookie['expires']);
150
-                $dt->setTimezone(new DateTimeZone('UTC'));
151
-                $cookie['expires'] = $dt->format(DateTime::ISO8601);
152
-            } catch (Exception $e) {
153
-                throw new HTTP_Request2_LogicException($e->getMessage());
154
-            }
155
-        }
156
-
157
-        if (empty($cookie['domain']) || empty($cookie['path'])) {
158
-            if (!$setter) {
159
-                throw new HTTP_Request2_LogicException(
160
-                    'Cookie misses domain and/or path component, cookie setter URL needed',
161
-                    HTTP_Request2_Exception::MISSING_VALUE
162
-                );
163
-            }
164
-            if (empty($cookie['domain'])) {
165
-                if ($host = $setter->getHost()) {
166
-                    $cookie['domain'] = $host;
167
-                } else {
168
-                    throw new HTTP_Request2_LogicException(
169
-                        'Setter URL does not contain host part, can\'t set cookie domain',
170
-                        HTTP_Request2_Exception::MISSING_VALUE
171
-                    );
172
-                }
173
-            }
174
-            if (empty($cookie['path'])) {
175
-                $path = $setter->getPath();
176
-                $cookie['path'] = empty($path)? '/': substr($path, 0, strrpos($path, '/') + 1);
177
-            }
178
-        }
179
-
180
-        if ($setter && !$this->domainMatch($setter->getHost(), $cookie['domain'])) {
181
-            throw new HTTP_Request2_MessageException(
182
-                "Domain " . $setter->getHost() . " cannot set cookies for "
183
-                . $cookie['domain']
184
-            );
185
-        }
186
-
187
-        return $cookie;
188
-    }
189
-
190
-    /**
191
-     * Stores a cookie in the jar
192
-     *
193
-     * @param array    $cookie cookie data, as returned by
194
-     *                         {@link HTTP_Request2_Response::getCookies()}
195
-     * @param Net_URL2 $setter URL of the document that sent Set-Cookie header
196
-     *
197
-     * @throws   HTTP_Request2_Exception
198
-     */
199
-    public function store(array $cookie, Net_URL2 $setter = null)
200
-    {
201
-        $cookie = $this->checkAndUpdateFields($cookie, $setter);
202
-
203
-        if (strlen($cookie['value'])
204
-            && (is_null($cookie['expires']) || $cookie['expires'] > $this->now())
205
-        ) {
206
-            if (!isset($this->cookies[$cookie['domain']])) {
207
-                $this->cookies[$cookie['domain']] = array();
208
-            }
209
-            if (!isset($this->cookies[$cookie['domain']][$cookie['path']])) {
210
-                $this->cookies[$cookie['domain']][$cookie['path']] = array();
211
-            }
212
-            $this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']] = $cookie;
213
-
214
-        } elseif (isset($this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']])) {
215
-            unset($this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']]);
216
-        }
217
-    }
218
-
219
-    /**
220
-     * Adds cookies set in HTTP response to the jar
221
-     *
222
-     * @param HTTP_Request2_Response $response HTTP response message
223
-     * @param Net_URL2               $setter   original request URL, needed for
224
-     *                               setting default domain/path
225
-     */
226
-    public function addCookiesFromResponse(HTTP_Request2_Response $response, Net_URL2 $setter)
227
-    {
228
-        foreach ($response->getCookies() as $cookie) {
229
-            $this->store($cookie, $setter);
230
-        }
231
-    }
232
-
233
-    /**
234
-     * Returns all cookies matching a given request URL
235
-     *
236
-     * The following checks are made:
237
-     *   - cookie domain should match request host
238
-     *   - cookie path should be a prefix for request path
239
-     *   - 'secure' cookies will only be sent for HTTPS requests
240
-     *
241
-     * @param Net_URL2 $url      Request url
242
-     * @param bool     $asString Whether to return cookies as string for "Cookie: " header
243
-     *
244
-     * @return array|string Matching cookies
245
-     */
246
-    public function getMatching(Net_URL2 $url, $asString = false)
247
-    {
248
-        $host   = $url->getHost();
249
-        $path   = $url->getPath();
250
-        $secure = 0 == strcasecmp($url->getScheme(), 'https');
251
-
252
-        $matched = $ret = array();
253
-        foreach (array_keys($this->cookies) as $domain) {
254
-            if ($this->domainMatch($host, $domain)) {
255
-                foreach (array_keys($this->cookies[$domain]) as $cPath) {
256
-                    if (0 === strpos($path, $cPath)) {
257
-                        foreach ($this->cookies[$domain][$cPath] as $name => $cookie) {
258
-                            if (!$cookie['secure'] || $secure) {
259
-                                $matched[$name][strlen($cookie['path'])] = $cookie;
260
-                            }
261
-                        }
262
-                    }
263
-                }
264
-            }
265
-        }
266
-        foreach ($matched as $cookies) {
267
-            krsort($cookies);
268
-            $ret = array_merge($ret, $cookies);
269
-        }
270
-        if (!$asString) {
271
-            return $ret;
272
-        } else {
273
-            $str = '';
274
-            foreach ($ret as $c) {
275
-                $str .= (empty($str)? '': '; ') . $c['name'] . '=' . $c['value'];
276
-            }
277
-            return $str;
278
-        }
279
-    }
280
-
281
-    /**
282
-     * Returns all cookies stored in a jar
283
-     *
284
-     * @return array
285
-     */
286
-    public function getAll()
287
-    {
288
-        $cookies = array();
289
-        foreach (array_keys($this->cookies) as $domain) {
290
-            foreach (array_keys($this->cookies[$domain]) as $path) {
291
-                foreach ($this->cookies[$domain][$path] as $name => $cookie) {
292
-                    $cookies[] = $cookie;
293
-                }
294
-            }
295
-        }
296
-        return $cookies;
297
-    }
298
-
299
-    /**
300
-     * Sets whether session cookies should be serialized when serializing the jar
301
-     *
302
-     * @param boolean $serialize serialize?
303
-     */
304
-    public function serializeSessionCookies($serialize)
305
-    {
306
-        $this->serializeSession = (bool)$serialize;
307
-    }
308
-
309
-    /**
310
-     * Sets whether Public Suffix List should be used for restricting cookie-setting
311
-     *
312
-     * Without PSL {@link domainMatch()} will only prevent setting cookies for
313
-     * top-level domains like '.com' or '.org'. However, it will not prevent
314
-     * setting a cookie for '.co.uk' even though only third-level registrations
315
-     * are possible in .uk domain.
316
-     *
317
-     * With the List it is possible to find the highest level at which a domain
318
-     * may be registered for a particular top-level domain and consequently
319
-     * prevent cookies set for '.co.uk' or '.msk.ru'. The same list is used by
320
-     * Firefox, Chrome and Opera browsers to restrict cookie setting.
321
-     *
322
-     * Note that PSL is licensed differently to HTTP_Request2 package (refer to
323
-     * the license information in public-suffix-list.php), so you can disable
324
-     * its use if this is an issue for you.
325
-     *
326
-     * @param boolean $useList use the list?
327
-     *
328
-     * @link     http://publicsuffix.org/learn/
329
-     */
330
-    public function usePublicSuffixList($useList)
331
-    {
332
-        $this->useList = (bool)$useList;
333
-    }
334
-
335
-    /**
336
-     * Returns string representation of object
337
-     *
338
-     * @return string
339
-     *
340
-     * @see    Serializable::serialize()
341
-     */
342
-    public function serialize()
343
-    {
344
-        $cookies = $this->getAll();
345
-        if (!$this->serializeSession) {
346
-            for ($i = count($cookies) - 1; $i >= 0; $i--) {
347
-                if (empty($cookies[$i]['expires'])) {
348
-                    unset($cookies[$i]);
349
-                }
350
-            }
351
-        }
352
-        return serialize(array(
353
-            'cookies'          => $cookies,
354
-            'serializeSession' => $this->serializeSession,
355
-            'useList'          => $this->useList
356
-        ));
357
-    }
358
-
359
-    /**
360
-     * Constructs the object from serialized string
361
-     *
362
-     * @param string $serialized string representation
363
-     *
364
-     * @see   Serializable::unserialize()
365
-     */
366
-    public function unserialize($serialized)
367
-    {
368
-        $data = unserialize($serialized);
369
-        $now  = $this->now();
370
-        $this->serializeSessionCookies($data['serializeSession']);
371
-        $this->usePublicSuffixList($data['useList']);
372
-        foreach ($data['cookies'] as $cookie) {
373
-            if (!empty($cookie['expires']) && $cookie['expires'] <= $now) {
374
-                continue;
375
-            }
376
-            if (!isset($this->cookies[$cookie['domain']])) {
377
-                $this->cookies[$cookie['domain']] = array();
378
-            }
379
-            if (!isset($this->cookies[$cookie['domain']][$cookie['path']])) {
380
-                $this->cookies[$cookie['domain']][$cookie['path']] = array();
381
-            }
382
-            $this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']] = $cookie;
383
-        }
384
-    }
385
-
386
-    /**
387
-     * Checks whether a cookie domain matches a request host.
388
-     *
389
-     * The method is used by {@link store()} to check for whether a document
390
-     * at given URL can set a cookie with a given domain attribute and by
391
-     * {@link getMatching()} to find cookies matching the request URL.
392
-     *
393
-     * @param string $requestHost  request host
394
-     * @param string $cookieDomain cookie domain
395
-     *
396
-     * @return   bool    match success
397
-     */
398
-    public function domainMatch($requestHost, $cookieDomain)
399
-    {
400
-        if ($requestHost == $cookieDomain) {
401
-            return true;
402
-        }
403
-        // IP address, we require exact match
404
-        if (preg_match('/^(?:\d{1,3}\.){3}\d{1,3}$/', $requestHost)) {
405
-            return false;
406
-        }
407
-        if ('.' != $cookieDomain[0]) {
408
-            $cookieDomain = '.' . $cookieDomain;
409
-        }
410
-        // prevents setting cookies for '.com' and similar domains
411
-        if (!$this->useList && substr_count($cookieDomain, '.') < 2
412
-            || $this->useList && !self::getRegisteredDomain($cookieDomain)
413
-        ) {
414
-            return false;
415
-        }
416
-        return substr('.' . $requestHost, -strlen($cookieDomain)) == $cookieDomain;
417
-    }
418
-
419
-    /**
420
-     * Removes subdomains to get the registered domain (the first after top-level)
421
-     *
422
-     * The method will check Public Suffix List to find out where top-level
423
-     * domain ends and registered domain starts. It will remove domain parts
424
-     * to the left of registered one.
425
-     *
426
-     * @param string $domain domain name
427
-     *
428
-     * @return string|bool   registered domain, will return false if $domain is
429
-     *                       either invalid or a TLD itself
430
-     */
431
-    public static function getRegisteredDomain($domain)
432
-    {
433
-        $domainParts = explode('.', ltrim($domain, '.'));
434
-
435
-        // load the list if needed
436
-        if (empty(self::$psl)) {
437
-            $path = '@data_dir@' . DIRECTORY_SEPARATOR . 'HTTP_Request2';
438
-            if (0 === strpos($path, '@' . 'data_dir@')) {
439
-                $path = realpath(
440
-                    dirname(__FILE__) . DIRECTORY_SEPARATOR . '..'
441
-                    . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data'
442
-                );
443
-            }
444
-            self::$psl = include_once $path . DIRECTORY_SEPARATOR . 'public-suffix-list.php';
445
-        }
446
-
447
-        if (!($result = self::checkDomainsList($domainParts, self::$psl))) {
448
-            // known TLD, invalid domain name
449
-            return false;
450
-        }
451
-
452
-        // unknown TLD
453
-        if (!strpos($result, '.')) {
454
-            // fallback to checking that domain "has at least two dots"
455
-            if (2 > ($count = count($domainParts))) {
456
-                return false;
457
-            }
458
-            return $domainParts[$count - 2] . '.' . $domainParts[$count - 1];
459
-        }
460
-        return $result;
461
-    }
462
-
463
-    /**
464
-     * Recursive helper method for {@link getRegisteredDomain()}
465
-     *
466
-     * @param array $domainParts remaining domain parts
467
-     * @param mixed $listNode    node in {@link HTTP_Request2_CookieJar::$psl} to check
468
-     *
469
-     * @return string|null   concatenated domain parts, null in case of error
470
-     */
471
-    protected static function checkDomainsList(array $domainParts, $listNode)
472
-    {
473
-        $sub    = array_pop($domainParts);
474
-        $result = null;
475
-
476
-        if (!is_array($listNode) || is_null($sub)
477
-            || array_key_exists('!' . $sub, $listNode)
478
-        ) {
479
-            return $sub;
480
-
481
-        } elseif (array_key_exists($sub, $listNode)) {
482
-            $result = self::checkDomainsList($domainParts, $listNode[$sub]);
483
-
484
-        } elseif (array_key_exists('*', $listNode)) {
485
-            $result = self::checkDomainsList($domainParts, $listNode['*']);
486
-
487
-        } else {
488
-            return $sub;
489
-        }
490
-
491
-        return (strlen($result) > 0) ? ($result . '.' . $sub) : null;
492
-    }
36
+	/**
37
+	 * Array of stored cookies
38
+	 *
39
+	 * The array is indexed by domain, path and cookie name
40
+	 *   .example.com
41
+	 *     /
42
+	 *       some_cookie => cookie data
43
+	 *     /subdir
44
+	 *       other_cookie => cookie data
45
+	 *   .example.org
46
+	 *     ...
47
+	 *
48
+	 * @var array
49
+	 */
50
+	protected $cookies = array();
51
+
52
+	/**
53
+	 * Whether session cookies should be serialized when serializing the jar
54
+	 * @var bool
55
+	 */
56
+	protected $serializeSession = false;
57
+
58
+	/**
59
+	 * Whether Public Suffix List should be used for domain matching
60
+	 * @var bool
61
+	 */
62
+	protected $useList = true;
63
+
64
+	/**
65
+	 * Array with Public Suffix List data
66
+	 * @var  array
67
+	 * @link http://publicsuffix.org/
68
+	 */
69
+	protected static $psl = array();
70
+
71
+	/**
72
+	 * Class constructor, sets various options
73
+	 *
74
+	 * @param bool $serializeSessionCookies Controls serializing session cookies,
75
+	 *                                      see {@link serializeSessionCookies()}
76
+	 * @param bool $usePublicSuffixList     Controls using Public Suffix List,
77
+	 *                                      see {@link usePublicSuffixList()}
78
+	 */
79
+	public function __construct(
80
+		$serializeSessionCookies = false, $usePublicSuffixList = true
81
+	) {
82
+		$this->serializeSessionCookies($serializeSessionCookies);
83
+		$this->usePublicSuffixList($usePublicSuffixList);
84
+	}
85
+
86
+	/**
87
+	 * Returns current time formatted in ISO-8601 at UTC timezone
88
+	 *
89
+	 * @return string
90
+	 */
91
+	protected function now()
92
+	{
93
+		$dt = new DateTime();
94
+		$dt->setTimezone(new DateTimeZone('UTC'));
95
+		return $dt->format(DateTime::ISO8601);
96
+	}
97
+
98
+	/**
99
+	 * Checks cookie array for correctness, possibly updating its 'domain', 'path' and 'expires' fields
100
+	 *
101
+	 * The checks are as follows:
102
+	 *   - cookie array should contain 'name' and 'value' fields;
103
+	 *   - name and value should not contain disallowed symbols;
104
+	 *   - 'expires' should be either empty parseable by DateTime;
105
+	 *   - 'domain' and 'path' should be either not empty or an URL where
106
+	 *     cookie was set should be provided.
107
+	 *   - if $setter is provided, then document at that URL should be allowed
108
+	 *     to set a cookie for that 'domain'. If $setter is not provided,
109
+	 *     then no domain checks will be made.
110
+	 *
111
+	 * 'expires' field will be converted to ISO8601 format from COOKIE format,
112
+	 * 'domain' and 'path' will be set from setter URL if empty.
113
+	 *
114
+	 * @param array    $cookie cookie data, as returned by
115
+	 *                         {@link HTTP_Request2_Response::getCookies()}
116
+	 * @param Net_URL2 $setter URL of the document that sent Set-Cookie header
117
+	 *
118
+	 * @return   array    Updated cookie array
119
+	 * @throws   HTTP_Request2_LogicException
120
+	 * @throws   HTTP_Request2_MessageException
121
+	 */
122
+	protected function checkAndUpdateFields(array $cookie, Net_URL2 $setter = null)
123
+	{
124
+		if ($missing = array_diff(array('name', 'value'), array_keys($cookie))) {
125
+			throw new HTTP_Request2_LogicException(
126
+				"Cookie array should contain 'name' and 'value' fields",
127
+				HTTP_Request2_Exception::MISSING_VALUE
128
+			);
129
+		}
130
+		if (preg_match(HTTP_Request2::REGEXP_INVALID_COOKIE, $cookie['name'])) {
131
+			throw new HTTP_Request2_LogicException(
132
+				"Invalid cookie name: '{$cookie['name']}'",
133
+				HTTP_Request2_Exception::INVALID_ARGUMENT
134
+			);
135
+		}
136
+		if (preg_match(HTTP_Request2::REGEXP_INVALID_COOKIE, $cookie['value'])) {
137
+			throw new HTTP_Request2_LogicException(
138
+				"Invalid cookie value: '{$cookie['value']}'",
139
+				HTTP_Request2_Exception::INVALID_ARGUMENT
140
+			);
141
+		}
142
+		$cookie += array('domain' => '', 'path' => '', 'expires' => null, 'secure' => false);
143
+
144
+		// Need ISO-8601 date @ UTC timezone
145
+		if (!empty($cookie['expires'])
146
+			&& !preg_match('/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\+0000$/', $cookie['expires'])
147
+		) {
148
+			try {
149
+				$dt = new DateTime($cookie['expires']);
150
+				$dt->setTimezone(new DateTimeZone('UTC'));
151
+				$cookie['expires'] = $dt->format(DateTime::ISO8601);
152
+			} catch (Exception $e) {
153
+				throw new HTTP_Request2_LogicException($e->getMessage());
154
+			}
155
+		}
156
+
157
+		if (empty($cookie['domain']) || empty($cookie['path'])) {
158
+			if (!$setter) {
159
+				throw new HTTP_Request2_LogicException(
160
+					'Cookie misses domain and/or path component, cookie setter URL needed',
161
+					HTTP_Request2_Exception::MISSING_VALUE
162
+				);
163
+			}
164
+			if (empty($cookie['domain'])) {
165
+				if ($host = $setter->getHost()) {
166
+					$cookie['domain'] = $host;
167
+				} else {
168
+					throw new HTTP_Request2_LogicException(
169
+						'Setter URL does not contain host part, can\'t set cookie domain',
170
+						HTTP_Request2_Exception::MISSING_VALUE
171
+					);
172
+				}
173
+			}
174
+			if (empty($cookie['path'])) {
175
+				$path = $setter->getPath();
176
+				$cookie['path'] = empty($path)? '/': substr($path, 0, strrpos($path, '/') + 1);
177
+			}
178
+		}
179
+
180
+		if ($setter && !$this->domainMatch($setter->getHost(), $cookie['domain'])) {
181
+			throw new HTTP_Request2_MessageException(
182
+				"Domain " . $setter->getHost() . " cannot set cookies for "
183
+				. $cookie['domain']
184
+			);
185
+		}
186
+
187
+		return $cookie;
188
+	}
189
+
190
+	/**
191
+	 * Stores a cookie in the jar
192
+	 *
193
+	 * @param array    $cookie cookie data, as returned by
194
+	 *                         {@link HTTP_Request2_Response::getCookies()}
195
+	 * @param Net_URL2 $setter URL of the document that sent Set-Cookie header
196
+	 *
197
+	 * @throws   HTTP_Request2_Exception
198
+	 */
199
+	public function store(array $cookie, Net_URL2 $setter = null)
200
+	{
201
+		$cookie = $this->checkAndUpdateFields($cookie, $setter);
202
+
203
+		if (strlen($cookie['value'])
204
+			&& (is_null($cookie['expires']) || $cookie['expires'] > $this->now())
205
+		) {
206
+			if (!isset($this->cookies[$cookie['domain']])) {
207
+				$this->cookies[$cookie['domain']] = array();
208
+			}
209
+			if (!isset($this->cookies[$cookie['domain']][$cookie['path']])) {
210
+				$this->cookies[$cookie['domain']][$cookie['path']] = array();
211
+			}
212
+			$this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']] = $cookie;
213
+
214
+		} elseif (isset($this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']])) {
215
+			unset($this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']]);
216
+		}
217
+	}
218
+
219
+	/**
220
+	 * Adds cookies set in HTTP response to the jar
221
+	 *
222
+	 * @param HTTP_Request2_Response $response HTTP response message
223
+	 * @param Net_URL2               $setter   original request URL, needed for
224
+	 *                               setting default domain/path
225
+	 */
226
+	public function addCookiesFromResponse(HTTP_Request2_Response $response, Net_URL2 $setter)
227
+	{
228
+		foreach ($response->getCookies() as $cookie) {
229
+			$this->store($cookie, $setter);
230
+		}
231
+	}
232
+
233
+	/**
234
+	 * Returns all cookies matching a given request URL
235
+	 *
236
+	 * The following checks are made:
237
+	 *   - cookie domain should match request host
238
+	 *   - cookie path should be a prefix for request path
239
+	 *   - 'secure' cookies will only be sent for HTTPS requests
240
+	 *
241
+	 * @param Net_URL2 $url      Request url
242
+	 * @param bool     $asString Whether to return cookies as string for "Cookie: " header
243
+	 *
244
+	 * @return array|string Matching cookies
245
+	 */
246
+	public function getMatching(Net_URL2 $url, $asString = false)
247
+	{
248
+		$host   = $url->getHost();
249
+		$path   = $url->getPath();
250
+		$secure = 0 == strcasecmp($url->getScheme(), 'https');
251
+
252
+		$matched = $ret = array();
253
+		foreach (array_keys($this->cookies) as $domain) {
254
+			if ($this->domainMatch($host, $domain)) {
255
+				foreach (array_keys($this->cookies[$domain]) as $cPath) {
256
+					if (0 === strpos($path, $cPath)) {
257
+						foreach ($this->cookies[$domain][$cPath] as $name => $cookie) {
258
+							if (!$cookie['secure'] || $secure) {
259
+								$matched[$name][strlen($cookie['path'])] = $cookie;
260
+							}
261
+						}
262
+					}
263
+				}
264
+			}
265
+		}
266
+		foreach ($matched as $cookies) {
267
+			krsort($cookies);
268
+			$ret = array_merge($ret, $cookies);
269
+		}
270
+		if (!$asString) {
271
+			return $ret;
272
+		} else {
273
+			$str = '';
274
+			foreach ($ret as $c) {
275
+				$str .= (empty($str)? '': '; ') . $c['name'] . '=' . $c['value'];
276
+			}
277
+			return $str;
278
+		}
279
+	}
280
+
281
+	/**
282
+	 * Returns all cookies stored in a jar
283
+	 *
284
+	 * @return array
285
+	 */
286
+	public function getAll()
287
+	{
288
+		$cookies = array();
289
+		foreach (array_keys($this->cookies) as $domain) {
290
+			foreach (array_keys($this->cookies[$domain]) as $path) {
291
+				foreach ($this->cookies[$domain][$path] as $name => $cookie) {
292
+					$cookies[] = $cookie;
293
+				}
294
+			}
295
+		}
296
+		return $cookies;
297
+	}
298
+
299
+	/**
300
+	 * Sets whether session cookies should be serialized when serializing the jar
301
+	 *
302
+	 * @param boolean $serialize serialize?
303
+	 */
304
+	public function serializeSessionCookies($serialize)
305
+	{
306
+		$this->serializeSession = (bool)$serialize;
307
+	}
308
+
309
+	/**
310
+	 * Sets whether Public Suffix List should be used for restricting cookie-setting
311
+	 *
312
+	 * Without PSL {@link domainMatch()} will only prevent setting cookies for
313
+	 * top-level domains like '.com' or '.org'. However, it will not prevent
314
+	 * setting a cookie for '.co.uk' even though only third-level registrations
315
+	 * are possible in .uk domain.
316
+	 *
317
+	 * With the List it is possible to find the highest level at which a domain
318
+	 * may be registered for a particular top-level domain and consequently
319
+	 * prevent cookies set for '.co.uk' or '.msk.ru'. The same list is used by
320
+	 * Firefox, Chrome and Opera browsers to restrict cookie setting.
321
+	 *
322
+	 * Note that PSL is licensed differently to HTTP_Request2 package (refer to
323
+	 * the license information in public-suffix-list.php), so you can disable
324
+	 * its use if this is an issue for you.
325
+	 *
326
+	 * @param boolean $useList use the list?
327
+	 *
328
+	 * @link     http://publicsuffix.org/learn/
329
+	 */
330
+	public function usePublicSuffixList($useList)
331
+	{
332
+		$this->useList = (bool)$useList;
333
+	}
334
+
335
+	/**
336
+	 * Returns string representation of object
337
+	 *
338
+	 * @return string
339
+	 *
340
+	 * @see    Serializable::serialize()
341
+	 */
342
+	public function serialize()
343
+	{
344
+		$cookies = $this->getAll();
345
+		if (!$this->serializeSession) {
346
+			for ($i = count($cookies) - 1; $i >= 0; $i--) {
347
+				if (empty($cookies[$i]['expires'])) {
348
+					unset($cookies[$i]);
349
+				}
350
+			}
351
+		}
352
+		return serialize(array(
353
+			'cookies'          => $cookies,
354
+			'serializeSession' => $this->serializeSession,
355
+			'useList'          => $this->useList
356
+		));
357
+	}
358
+
359
+	/**
360
+	 * Constructs the object from serialized string
361
+	 *
362
+	 * @param string $serialized string representation
363
+	 *
364
+	 * @see   Serializable::unserialize()
365
+	 */
366
+	public function unserialize($serialized)
367
+	{
368
+		$data = unserialize($serialized);
369
+		$now  = $this->now();
370
+		$this->serializeSessionCookies($data['serializeSession']);
371
+		$this->usePublicSuffixList($data['useList']);
372
+		foreach ($data['cookies'] as $cookie) {
373
+			if (!empty($cookie['expires']) && $cookie['expires'] <= $now) {
374
+				continue;
375
+			}
376
+			if (!isset($this->cookies[$cookie['domain']])) {
377
+				$this->cookies[$cookie['domain']] = array();
378
+			}
379
+			if (!isset($this->cookies[$cookie['domain']][$cookie['path']])) {
380
+				$this->cookies[$cookie['domain']][$cookie['path']] = array();
381
+			}
382
+			$this->cookies[$cookie['domain']][$cookie['path']][$cookie['name']] = $cookie;
383
+		}
384
+	}
385
+
386
+	/**
387
+	 * Checks whether a cookie domain matches a request host.
388
+	 *
389
+	 * The method is used by {@link store()} to check for whether a document
390
+	 * at given URL can set a cookie with a given domain attribute and by
391
+	 * {@link getMatching()} to find cookies matching the request URL.
392
+	 *
393
+	 * @param string $requestHost  request host
394
+	 * @param string $cookieDomain cookie domain
395
+	 *
396
+	 * @return   bool    match success
397
+	 */
398
+	public function domainMatch($requestHost, $cookieDomain)
399
+	{
400
+		if ($requestHost == $cookieDomain) {
401
+			return true;
402
+		}
403
+		// IP address, we require exact match
404
+		if (preg_match('/^(?:\d{1,3}\.){3}\d{1,3}$/', $requestHost)) {
405
+			return false;
406
+		}
407
+		if ('.' != $cookieDomain[0]) {
408
+			$cookieDomain = '.' . $cookieDomain;
409
+		}
410
+		// prevents setting cookies for '.com' and similar domains
411
+		if (!$this->useList && substr_count($cookieDomain, '.') < 2
412
+			|| $this->useList && !self::getRegisteredDomain($cookieDomain)
413
+		) {
414
+			return false;
415
+		}
416
+		return substr('.' . $requestHost, -strlen($cookieDomain)) == $cookieDomain;
417
+	}
418
+
419
+	/**
420
+	 * Removes subdomains to get the registered domain (the first after top-level)
421
+	 *
422
+	 * The method will check Public Suffix List to find out where top-level
423
+	 * domain ends and registered domain starts. It will remove domain parts
424
+	 * to the left of registered one.
425
+	 *
426
+	 * @param string $domain domain name
427
+	 *
428
+	 * @return string|bool   registered domain, will return false if $domain is
429
+	 *                       either invalid or a TLD itself
430
+	 */
431
+	public static function getRegisteredDomain($domain)
432
+	{
433
+		$domainParts = explode('.', ltrim($domain, '.'));
434
+
435
+		// load the list if needed
436
+		if (empty(self::$psl)) {
437
+			$path = '@data_dir@' . DIRECTORY_SEPARATOR . 'HTTP_Request2';
438
+			if (0 === strpos($path, '@' . 'data_dir@')) {
439
+				$path = realpath(
440
+					dirname(__FILE__) . DIRECTORY_SEPARATOR . '..'
441
+					. DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data'
442
+				);
443
+			}
444
+			self::$psl = include_once $path . DIRECTORY_SEPARATOR . 'public-suffix-list.php';
445
+		}
446
+
447
+		if (!($result = self::checkDomainsList($domainParts, self::$psl))) {
448
+			// known TLD, invalid domain name
449
+			return false;
450
+		}
451
+
452
+		// unknown TLD
453
+		if (!strpos($result, '.')) {
454
+			// fallback to checking that domain "has at least two dots"
455
+			if (2 > ($count = count($domainParts))) {
456
+				return false;
457
+			}
458
+			return $domainParts[$count - 2] . '.' . $domainParts[$count - 1];
459
+		}
460
+		return $result;
461
+	}
462
+
463
+	/**
464
+	 * Recursive helper method for {@link getRegisteredDomain()}
465
+	 *
466
+	 * @param array $domainParts remaining domain parts
467
+	 * @param mixed $listNode    node in {@link HTTP_Request2_CookieJar::$psl} to check
468
+	 *
469
+	 * @return string|null   concatenated domain parts, null in case of error
470
+	 */
471
+	protected static function checkDomainsList(array $domainParts, $listNode)
472
+	{
473
+		$sub    = array_pop($domainParts);
474
+		$result = null;
475
+
476
+		if (!is_array($listNode) || is_null($sub)
477
+			|| array_key_exists('!' . $sub, $listNode)
478
+		) {
479
+			return $sub;
480
+
481
+		} elseif (array_key_exists($sub, $listNode)) {
482
+			$result = self::checkDomainsList($domainParts, $listNode[$sub]);
483
+
484
+		} elseif (array_key_exists('*', $listNode)) {
485
+			$result = self::checkDomainsList($domainParts, $listNode['*']);
486
+
487
+		} else {
488
+			return $sub;
489
+		}
490
+
491
+		return (strlen($result) > 0) ? ($result . '.' . $sub) : null;
492
+	}
493 493
 }
494 494
 ?>
495 495
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -173,13 +173,13 @@  discard block
 block discarded – undo
173 173
             }
174 174
             if (empty($cookie['path'])) {
175 175
                 $path = $setter->getPath();
176
-                $cookie['path'] = empty($path)? '/': substr($path, 0, strrpos($path, '/') + 1);
176
+                $cookie['path'] = empty($path) ? '/' : substr($path, 0, strrpos($path, '/') + 1);
177 177
             }
178 178
         }
179 179
 
180 180
         if ($setter && !$this->domainMatch($setter->getHost(), $cookie['domain'])) {
181 181
             throw new HTTP_Request2_MessageException(
182
-                "Domain " . $setter->getHost() . " cannot set cookies for "
182
+                "Domain ".$setter->getHost()." cannot set cookies for "
183 183
                 . $cookie['domain']
184 184
             );
185 185
         }
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
         } else {
273 273
             $str = '';
274 274
             foreach ($ret as $c) {
275
-                $str .= (empty($str)? '': '; ') . $c['name'] . '=' . $c['value'];
275
+                $str .= (empty($str) ? '' : '; ').$c['name'].'='.$c['value'];
276 276
             }
277 277
             return $str;
278 278
         }
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
      */
304 304
     public function serializeSessionCookies($serialize)
305 305
     {
306
-        $this->serializeSession = (bool)$serialize;
306
+        $this->serializeSession = (bool) $serialize;
307 307
     }
308 308
 
309 309
     /**
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
      */
330 330
     public function usePublicSuffixList($useList)
331 331
     {
332
-        $this->useList = (bool)$useList;
332
+        $this->useList = (bool) $useList;
333 333
     }
334 334
 
335 335
     /**
@@ -405,7 +405,7 @@  discard block
 block discarded – undo
405 405
             return false;
406 406
         }
407 407
         if ('.' != $cookieDomain[0]) {
408
-            $cookieDomain = '.' . $cookieDomain;
408
+            $cookieDomain = '.'.$cookieDomain;
409 409
         }
410 410
         // prevents setting cookies for '.com' and similar domains
411 411
         if (!$this->useList && substr_count($cookieDomain, '.') < 2
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
         ) {
414 414
             return false;
415 415
         }
416
-        return substr('.' . $requestHost, -strlen($cookieDomain)) == $cookieDomain;
416
+        return substr('.'.$requestHost, -strlen($cookieDomain)) == $cookieDomain;
417 417
     }
418 418
 
419 419
     /**
@@ -434,14 +434,14 @@  discard block
 block discarded – undo
434 434
 
435 435
         // load the list if needed
436 436
         if (empty(self::$psl)) {
437
-            $path = '@data_dir@' . DIRECTORY_SEPARATOR . 'HTTP_Request2';
438
-            if (0 === strpos($path, '@' . 'data_dir@')) {
437
+            $path = '@data_dir@'.DIRECTORY_SEPARATOR.'HTTP_Request2';
438
+            if (0 === strpos($path, '@'.'data_dir@')) {
439 439
                 $path = realpath(
440
-                    dirname(__FILE__) . DIRECTORY_SEPARATOR . '..'
441
-                    . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'data'
440
+                    dirname(__FILE__).DIRECTORY_SEPARATOR.'..'
441
+                    . DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'data'
442 442
                 );
443 443
             }
444
-            self::$psl = include_once $path . DIRECTORY_SEPARATOR . 'public-suffix-list.php';
444
+            self::$psl = include_once $path.DIRECTORY_SEPARATOR.'public-suffix-list.php';
445 445
         }
446 446
 
447 447
         if (!($result = self::checkDomainsList($domainParts, self::$psl))) {
@@ -455,7 +455,7 @@  discard block
 block discarded – undo
455 455
             if (2 > ($count = count($domainParts))) {
456 456
                 return false;
457 457
             }
458
-            return $domainParts[$count - 2] . '.' . $domainParts[$count - 1];
458
+            return $domainParts[$count - 2].'.'.$domainParts[$count - 1];
459 459
         }
460 460
         return $result;
461 461
     }
@@ -474,7 +474,7 @@  discard block
 block discarded – undo
474 474
         $result = null;
475 475
 
476 476
         if (!is_array($listNode) || is_null($sub)
477
-            || array_key_exists('!' . $sub, $listNode)
477
+            || array_key_exists('!'.$sub, $listNode)
478 478
         ) {
479 479
             return $sub;
480 480
 
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
             return $sub;
489 489
         }
490 490
 
491
-        return (strlen($result) > 0) ? ($result . '.' . $sub) : null;
491
+        return (strlen($result) > 0) ? ($result.'.'.$sub) : null;
492 492
     }
493 493
 }
494 494
 ?>
495 495
\ No newline at end of file
Please login to merge, or discard this patch.
libs/PEAR.1.9.5/Net/URL2.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
      * Returns the user part of the userinfo part (the part preceding the first
230 230
      *  ":"), or false if there is no userinfo part.
231 231
      *
232
-     * @return string|bool
232
+     * @return string|false
233 233
      */
234 234
     public function getUser()
235 235
     {
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      * contain "@" in front of the hostname) or the userinfo part does not
245 245
      * contain ":".
246 246
      *
247
-     * @return string|bool
247
+     * @return string|false
248 248
      */
249 249
     public function getPassword()
250 250
     {
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
      * Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or
342 342
      * false if there is no authority.
343 343
      *
344
-     * @return string|bool
344
+     * @return false|string
345 345
      */
346 346
     public function getAuthority()
347 347
     {
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
      * Returns an Net_URL2 instance representing an absolute URL relative to
875 875
      * this URL.
876 876
      *
877
-     * @param Net_URL2|string $reference relative URL
877
+     * @param Net_URL2 $reference relative URL
878 878
      *
879 879
      * @throws Exception
880 880
      * @return $this
@@ -1047,7 +1047,7 @@  discard block
 block discarded – undo
1047 1047
      * currently executing PHP script.
1048 1048
      *
1049 1049
      * @throws Exception
1050
-     * @return string
1050
+     * @return Net_URL2
1051 1051
      */
1052 1052
     public static function getCanonical()
1053 1053
     {
@@ -1106,7 +1106,7 @@  discard block
 block discarded – undo
1106 1106
      *
1107 1107
      * @param string $optionName The name of the option to retrieve
1108 1108
      *
1109
-     * @return mixed
1109
+     * @return string
1110 1110
      */
1111 1111
     public function getOption($optionName)
1112 1112
     {
Please login to merge, or discard this patch.
Indentation   +1160 added lines, -1160 removed lines patch added patch discarded remove patch
@@ -56,1164 +56,1164 @@
 block discarded – undo
56 56
  */
57 57
 class Net_URL2
58 58
 {
59
-    /**
60
-     * Do strict parsing in resolve() (see RFC 3986, section 5.2.2). Default
61
-     * is true.
62
-     */
63
-    const OPTION_STRICT = 'strict';
64
-
65
-    /**
66
-     * Represent arrays in query using PHP's [] notation. Default is true.
67
-     */
68
-    const OPTION_USE_BRACKETS = 'use_brackets';
69
-
70
-    /**
71
-     * Drop zero-based integer sequences in query using PHP's [] notation. Default
72
-     * is true.
73
-     */
74
-    const OPTION_DROP_SEQUENCE = 'drop_sequence';
75
-
76
-    /**
77
-     * URL-encode query variable keys. Default is true.
78
-     */
79
-    const OPTION_ENCODE_KEYS = 'encode_keys';
80
-
81
-    /**
82
-     * Query variable separators when parsing the query string. Every character
83
-     * is considered a separator. Default is "&".
84
-     */
85
-    const OPTION_SEPARATOR_INPUT = 'input_separator';
86
-
87
-    /**
88
-     * Query variable separator used when generating the query string. Default
89
-     * is "&".
90
-     */
91
-    const OPTION_SEPARATOR_OUTPUT = 'output_separator';
92
-
93
-    /**
94
-     * Default options corresponds to how PHP handles $_GET.
95
-     */
96
-    private $_options = array(
97
-        self::OPTION_STRICT           => true,
98
-        self::OPTION_USE_BRACKETS     => true,
99
-        self::OPTION_DROP_SEQUENCE    => true,
100
-        self::OPTION_ENCODE_KEYS      => true,
101
-        self::OPTION_SEPARATOR_INPUT  => '&',
102
-        self::OPTION_SEPARATOR_OUTPUT => '&',
103
-        );
104
-
105
-    /**
106
-     * @var  string|bool
107
-     */
108
-    private $_scheme = false;
109
-
110
-    /**
111
-     * @var  string|bool
112
-     */
113
-    private $_userinfo = false;
114
-
115
-    /**
116
-     * @var  string|bool
117
-     */
118
-    private $_host = false;
119
-
120
-    /**
121
-     * @var  string|bool
122
-     */
123
-    private $_port = false;
124
-
125
-    /**
126
-     * @var  string
127
-     */
128
-    private $_path = '';
129
-
130
-    /**
131
-     * @var  string|bool
132
-     */
133
-    private $_query = false;
134
-
135
-    /**
136
-     * @var  string|bool
137
-     */
138
-    private $_fragment = false;
139
-
140
-    /**
141
-     * Constructor.
142
-     *
143
-     * @param string $url     an absolute or relative URL
144
-     * @param array  $options an array of OPTION_xxx constants
145
-     *
146
-     * @uses   self::parseUrl()
147
-     */
148
-    public function __construct($url, array $options = array())
149
-    {
150
-        foreach ($options as $optionName => $value) {
151
-            if (array_key_exists($optionName, $this->_options)) {
152
-                $this->_options[$optionName] = $value;
153
-            }
154
-        }
155
-
156
-        $this->parseUrl($url);
157
-    }
158
-
159
-    /**
160
-     * Magic Setter.
161
-     *
162
-     * This method will magically set the value of a private variable ($var)
163
-     * with the value passed as the args
164
-     *
165
-     * @param string $var The private variable to set.
166
-     * @param mixed  $arg An argument of any type.
167
-     *
168
-     * @return void
169
-     */
170
-    public function __set($var, $arg)
171
-    {
172
-        $method = 'set' . $var;
173
-        if (method_exists($this, $method)) {
174
-            $this->$method($arg);
175
-        }
176
-    }
177
-
178
-    /**
179
-     * Magic Getter.
180
-     *
181
-     * This is the magic get method to retrieve the private variable
182
-     * that was set by either __set() or it's setter...
183
-     *
184
-     * @param string $var The property name to retrieve.
185
-     *
186
-     * @return mixed  $this->$var Either a boolean false if the
187
-     *                            property is not set or the value
188
-     *                            of the private property.
189
-     */
190
-    public function __get($var)
191
-    {
192
-        $method = 'get' . $var;
193
-        if (method_exists($this, $method)) {
194
-            return $this->$method();
195
-        }
196
-
197
-        return false;
198
-    }
199
-
200
-    /**
201
-     * Returns the scheme, e.g. "http" or "urn", or false if there is no
202
-     * scheme specified, i.e. if this is a relative URL.
203
-     *
204
-     * @return string|bool
205
-     */
206
-    public function getScheme()
207
-    {
208
-        return $this->_scheme;
209
-    }
210
-
211
-    /**
212
-     * Sets the scheme, e.g. "http" or "urn". Specify false if there is no
213
-     * scheme specified, i.e. if this is a relative URL.
214
-     *
215
-     * @param string|bool $scheme e.g. "http" or "urn", or false if there is no
216
-     *                            scheme specified, i.e. if this is a relative
217
-     *                            URL
218
-     *
219
-     * @return $this
220
-     * @see    getScheme
221
-     */
222
-    public function setScheme($scheme)
223
-    {
224
-        $this->_scheme = $scheme;
225
-        return $this;
226
-    }
227
-
228
-    /**
229
-     * Returns the user part of the userinfo part (the part preceding the first
230
-     *  ":"), or false if there is no userinfo part.
231
-     *
232
-     * @return string|bool
233
-     */
234
-    public function getUser()
235
-    {
236
-        return $this->_userinfo !== false
237
-            ? preg_replace('(:.*$)', '', $this->_userinfo)
238
-            : false;
239
-    }
240
-
241
-    /**
242
-     * Returns the password part of the userinfo part (the part after the first
243
-     *  ":"), or false if there is no userinfo part (i.e. the URL does not
244
-     * contain "@" in front of the hostname) or the userinfo part does not
245
-     * contain ":".
246
-     *
247
-     * @return string|bool
248
-     */
249
-    public function getPassword()
250
-    {
251
-        return $this->_userinfo !== false
252
-            ? substr(strstr($this->_userinfo, ':'), 1)
253
-            : false;
254
-    }
255
-
256
-    /**
257
-     * Returns the userinfo part, or false if there is none, i.e. if the
258
-     * authority part does not contain "@".
259
-     *
260
-     * @return string|bool
261
-     */
262
-    public function getUserinfo()
263
-    {
264
-        return $this->_userinfo;
265
-    }
266
-
267
-    /**
268
-     * Sets the userinfo part. If two arguments are passed, they are combined
269
-     * in the userinfo part as username ":" password.
270
-     *
271
-     * @param string|bool $userinfo userinfo or username
272
-     * @param string|bool $password optional password, or false
273
-     *
274
-     * @return $this
275
-     */
276
-    public function setUserinfo($userinfo, $password = false)
277
-    {
278
-        if ($password !== false) {
279
-            $userinfo .= ':' . $password;
280
-        }
281
-
282
-        if ($userinfo !== false) {
283
-            $userinfo = $this->_encodeData($userinfo);
284
-        }
285
-
286
-        $this->_userinfo = $userinfo;
287
-        return $this;
288
-    }
289
-
290
-    /**
291
-     * Returns the host part, or false if there is no authority part, e.g.
292
-     * relative URLs.
293
-     *
294
-     * @return string|bool a hostname, an IP address, or false
295
-     */
296
-    public function getHost()
297
-    {
298
-        return $this->_host;
299
-    }
300
-
301
-    /**
302
-     * Sets the host part. Specify false if there is no authority part, e.g.
303
-     * relative URLs.
304
-     *
305
-     * @param string|bool $host a hostname, an IP address, or false
306
-     *
307
-     * @return $this
308
-     */
309
-    public function setHost($host)
310
-    {
311
-        $this->_host = $host;
312
-        return $this;
313
-    }
314
-
315
-    /**
316
-     * Returns the port number, or false if there is no port number specified,
317
-     * i.e. if the default port is to be used.
318
-     *
319
-     * @return string|bool
320
-     */
321
-    public function getPort()
322
-    {
323
-        return $this->_port;
324
-    }
325
-
326
-    /**
327
-     * Sets the port number. Specify false if there is no port number specified,
328
-     * i.e. if the default port is to be used.
329
-     *
330
-     * @param string|bool $port a port number, or false
331
-     *
332
-     * @return $this
333
-     */
334
-    public function setPort($port)
335
-    {
336
-        $this->_port = $port;
337
-        return $this;
338
-    }
339
-
340
-    /**
341
-     * Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or
342
-     * false if there is no authority.
343
-     *
344
-     * @return string|bool
345
-     */
346
-    public function getAuthority()
347
-    {
348
-        if (false === $this->_host) {
349
-            return false;
350
-        }
351
-
352
-        $authority = '';
353
-
354
-        if (strlen($this->_userinfo)) {
355
-            $authority .= $this->_userinfo . '@';
356
-        }
357
-
358
-        $authority .= $this->_host;
359
-
360
-        if ($this->_port !== false) {
361
-            $authority .= ':' . $this->_port;
362
-        }
363
-
364
-        return $authority;
365
-    }
366
-
367
-    /**
368
-     * Sets the authority part, i.e. [ userinfo "@" ] host [ ":" port ]. Specify
369
-     * false if there is no authority.
370
-     *
371
-     * @param string|bool $authority a hostname or an IP address, possibly
372
-     *                                with userinfo prefixed and port number
373
-     *                                appended, e.g. "foo:[email protected]:81".
374
-     *
375
-     * @return $this
376
-     */
377
-    public function setAuthority($authority)
378
-    {
379
-        $this->_userinfo = false;
380
-        $this->_host     = false;
381
-        $this->_port     = false;
382
-
383
-        if ('' === $authority) {
384
-            $this->_host = $authority;
385
-            return $this;
386
-        }
387
-
388
-        if (!preg_match('(^(([^\@]*)\@)?(.+?)(:(\d*))?$)', $authority, $matches)) {
389
-            return $this;
390
-        }
391
-
392
-        if ($matches[1]) {
393
-            $this->_userinfo = $this->_encodeData($matches[2]);
394
-        }
395
-
396
-        $this->_host = $matches[3];
397
-
398
-        if (isset($matches[5]) && strlen($matches[5])) {
399
-            $this->_port = $matches[5];
400
-        }
401
-        return $this;
402
-    }
403
-
404
-    /**
405
-     * Returns the path part (possibly an empty string).
406
-     *
407
-     * @return string
408
-     */
409
-    public function getPath()
410
-    {
411
-        return $this->_path;
412
-    }
413
-
414
-    /**
415
-     * Sets the path part (possibly an empty string).
416
-     *
417
-     * @param string $path a path
418
-     *
419
-     * @return $this
420
-     */
421
-    public function setPath($path)
422
-    {
423
-        $this->_path = $path;
424
-        return $this;
425
-    }
426
-
427
-    /**
428
-     * Returns the query string (excluding the leading "?"), or false if "?"
429
-     * is not present in the URL.
430
-     *
431
-     * @return  string|bool
432
-     * @see     getQueryVariables
433
-     */
434
-    public function getQuery()
435
-    {
436
-        return $this->_query;
437
-    }
438
-
439
-    /**
440
-     * Sets the query string (excluding the leading "?"). Specify false if "?"
441
-     * is not present in the URL.
442
-     *
443
-     * @param string|bool $query a query string, e.g. "foo=1&bar=2"
444
-     *
445
-     * @return $this
446
-     * @see    setQueryVariables
447
-     */
448
-    public function setQuery($query)
449
-    {
450
-        $this->_query = $query;
451
-        return $this;
452
-    }
453
-
454
-    /**
455
-     * Returns the fragment name, or false if "#" is not present in the URL.
456
-     *
457
-     * @return string|bool
458
-     */
459
-    public function getFragment()
460
-    {
461
-        return $this->_fragment;
462
-    }
463
-
464
-    /**
465
-     * Sets the fragment name. Specify false if "#" is not present in the URL.
466
-     *
467
-     * @param string|bool $fragment a fragment excluding the leading "#", or
468
-     *                              false
469
-     *
470
-     * @return $this
471
-     */
472
-    public function setFragment($fragment)
473
-    {
474
-        $this->_fragment = $fragment;
475
-        return $this;
476
-    }
477
-
478
-    /**
479
-     * Returns the query string like an array as the variables would appear in
480
-     * $_GET in a PHP script. If the URL does not contain a "?", an empty array
481
-     * is returned.
482
-     *
483
-     * @return array
484
-     */
485
-    public function getQueryVariables()
486
-    {
487
-        $separator   = $this->getOption(self::OPTION_SEPARATOR_INPUT);
488
-        $encodeKeys  = $this->getOption(self::OPTION_ENCODE_KEYS);
489
-        $useBrackets = $this->getOption(self::OPTION_USE_BRACKETS);
490
-
491
-        $return  = array();
492
-
493
-        for ($part = strtok($this->_query, $separator);
494
-            strlen($part);
495
-            $part = strtok($separator)
496
-        ) {
497
-            list($key, $value) = explode('=', $part, 2) + array(1 => '');
498
-
499
-            if ($encodeKeys) {
500
-                $key = rawurldecode($key);
501
-            }
502
-            $value = rawurldecode($value);
503
-
504
-            if ($useBrackets) {
505
-                $return = $this->_queryArrayByKey($key, $value, $return);
506
-            } else {
507
-                if (isset($return[$key])) {
508
-                    $return[$key]  = (array) $return[$key];
509
-                    $return[$key][] = $value;
510
-                } else {
511
-                    $return[$key] = $value;
512
-                }
513
-            }
514
-        }
515
-
516
-        return $return;
517
-    }
518
-
519
-    /**
520
-     * Parse a single query key=value pair into an existing php array
521
-     *
522
-     * @param string $key   query-key
523
-     * @param string $value query-value
524
-     * @param array  $array of existing query variables (if any)
525
-     *
526
-     * @return mixed
527
-     */
528
-    private function _queryArrayByKey($key, $value, array $array = array())
529
-    {
530
-        if (!strlen($key)) {
531
-            return $array;
532
-        }
533
-
534
-        $offset = $this->_queryKeyBracketOffset($key);
535
-        if ($offset === false) {
536
-            $name = $key;
537
-        } else {
538
-            $name = substr($key, 0, $offset);
539
-        }
540
-
541
-        if (!strlen($name)) {
542
-            return $array;
543
-        }
544
-
545
-        if (!$offset) {
546
-            // named value
547
-            $array[$name] = $value;
548
-        } else {
549
-            // array
550
-            $brackets = substr($key, $offset);
551
-            if (!isset($array[$name])) {
552
-                $array[$name] = null;
553
-            }
554
-            $array[$name] = $this->_queryArrayByBrackets(
555
-                $brackets, $value, $array[$name]
556
-            );
557
-        }
558
-
559
-        return $array;
560
-    }
561
-
562
-    /**
563
-     * Parse a key-buffer to place value in array
564
-     *
565
-     * @param string $buffer to consume all keys from
566
-     * @param string $value  to be set/add
567
-     * @param array  $array  to traverse and set/add value in
568
-     *
569
-     * @throws Exception
570
-     * @return array
571
-     */
572
-    private function _queryArrayByBrackets($buffer, $value, array $array = null)
573
-    {
574
-        $entry = &$array;
575
-
576
-        for ($iteration = 0; strlen($buffer); $iteration++) {
577
-            $open = $this->_queryKeyBracketOffset($buffer);
578
-            if ($open !== 0) {
579
-                // Opening bracket [ must exist at offset 0, if not, there is
580
-                // no bracket to parse and the value dropped.
581
-                // if this happens in the first iteration, this is flawed, see
582
-                // as well the second exception below.
583
-                if ($iteration) {
584
-                    break;
585
-                }
586
-                // @codeCoverageIgnoreStart
587
-                throw new Exception(
588
-                    'Net_URL2 Internal Error: '. __METHOD__ .'(): ' .
589
-                    'Opening bracket [ must exist at offset 0'
590
-                );
591
-                // @codeCoverageIgnoreEnd
592
-            }
593
-
594
-            $close = strpos($buffer, ']', 1);
595
-            if (!$close) {
596
-                // this error condition should never be reached as this is a
597
-                // private method and bracket pairs are checked beforehand.
598
-                // See as well the first exception for the opening bracket.
599
-                // @codeCoverageIgnoreStart
600
-                throw new Exception(
601
-                    'Net_URL2 Internal Error: '. __METHOD__ .'(): ' .
602
-                    'Closing bracket ] must exist, not found'
603
-                );
604
-                // @codeCoverageIgnoreEnd
605
-            }
606
-
607
-            $index = substr($buffer, 1, $close - 1);
608
-            if (strlen($index)) {
609
-                $entry = &$entry[$index];
610
-            } else {
611
-                if (!is_array($entry)) {
612
-                    $entry = array();
613
-                }
614
-                $entry[] = &$new;
615
-                $entry = &$new;
616
-                unset($new);
617
-            }
618
-            $buffer = substr($buffer, $close + 1);
619
-        }
620
-
621
-        $entry = $value;
622
-
623
-        return $array;
624
-    }
625
-
626
-    /**
627
-     * Query-key has brackets ("...[]")
628
-     *
629
-     * @param string $key query-key
630
-     *
631
-     * @return bool|int offset of opening bracket, false if no brackets
632
-     */
633
-    private function _queryKeyBracketOffset($key)
634
-    {
635
-        if (false !== $open = strpos($key, '[')
636
-            and false === strpos($key, ']', $open + 1)
637
-        ) {
638
-            $open = false;
639
-        }
640
-
641
-        return $open;
642
-    }
643
-
644
-    /**
645
-     * Sets the query string to the specified variable in the query string.
646
-     *
647
-     * @param array $array (name => value) array
648
-     *
649
-     * @return $this
650
-     */
651
-    public function setQueryVariables(array $array)
652
-    {
653
-        if (!$array) {
654
-            $this->_query = false;
655
-        } else {
656
-            $this->_query = $this->buildQuery(
657
-                $array,
658
-                $this->getOption(self::OPTION_SEPARATOR_OUTPUT)
659
-            );
660
-        }
661
-        return $this;
662
-    }
663
-
664
-    /**
665
-     * Sets the specified variable in the query string.
666
-     *
667
-     * @param string $name  variable name
668
-     * @param mixed  $value variable value
669
-     *
670
-     * @return $this
671
-     */
672
-    public function setQueryVariable($name, $value)
673
-    {
674
-        $array = $this->getQueryVariables();
675
-        $array[$name] = $value;
676
-        $this->setQueryVariables($array);
677
-        return $this;
678
-    }
679
-
680
-    /**
681
-     * Removes the specified variable from the query string.
682
-     *
683
-     * @param string $name a query string variable, e.g. "foo" in "?foo=1"
684
-     *
685
-     * @return void
686
-     */
687
-    public function unsetQueryVariable($name)
688
-    {
689
-        $array = $this->getQueryVariables();
690
-        unset($array[$name]);
691
-        $this->setQueryVariables($array);
692
-    }
693
-
694
-    /**
695
-     * Returns a string representation of this URL.
696
-     *
697
-     * @return string
698
-     */
699
-    public function getURL()
700
-    {
701
-        // See RFC 3986, section 5.3
702
-        $url = '';
703
-
704
-        if ($this->_scheme !== false) {
705
-            $url .= $this->_scheme . ':';
706
-        }
707
-
708
-        $authority = $this->getAuthority();
709
-        if ($authority === false && strtolower($this->_scheme) === 'file') {
710
-            $authority = '';
711
-        }
712
-
713
-        $url .= $this->_buildAuthorityAndPath($authority, $this->_path);
714
-
715
-        if ($this->_query !== false) {
716
-            $url .= '?' . $this->_query;
717
-        }
718
-
719
-        if ($this->_fragment !== false) {
720
-            $url .= '#' . $this->_fragment;
721
-        }
722
-
723
-        return $url;
724
-    }
725
-
726
-    /**
727
-     * Put authority and path together, wrapping authority
728
-     * into proper separators/terminators.
729
-     *
730
-     * @param string|bool $authority authority
731
-     * @param string      $path      path
732
-     *
733
-     * @return string
734
-     */
735
-    private function _buildAuthorityAndPath($authority, $path)
736
-    {
737
-        if ($authority === false) {
738
-            return $path;
739
-        }
740
-
741
-        $terminator = ($path !== '' && $path[0] !== '/') ? '/' : '';
742
-
743
-        return '//' . $authority . $terminator . $path;
744
-    }
745
-
746
-    /**
747
-     * Returns a string representation of this URL.
748
-     *
749
-     * @return string
750
-     * @link https://php.net/language.oop5.magic#object.tostring
751
-     */
752
-    public function __toString()
753
-    {
754
-        return $this->getURL();
755
-    }
756
-
757
-    /**
758
-     * Returns a normalized string representation of this URL. This is useful
759
-     * for comparison of URLs.
760
-     *
761
-     * @return string
762
-     */
763
-    public function getNormalizedURL()
764
-    {
765
-        $url = clone $this;
766
-        $url->normalize();
767
-        return $url->getUrl();
768
-    }
769
-
770
-    /**
771
-     * Normalizes the URL
772
-     *
773
-     * See RFC 3986, Section 6.  Normalization and Comparison
774
-     *
775
-     * @link https://tools.ietf.org/html/rfc3986#section-6
776
-     *
777
-     * @return void
778
-     */
779
-    public function normalize()
780
-    {
781
-        // See RFC 3986, section 6
782
-
783
-        // Scheme is case-insensitive
784
-        if ($this->_scheme) {
785
-            $this->_scheme = strtolower($this->_scheme);
786
-        }
787
-
788
-        // Hostname is case-insensitive
789
-        if ($this->_host) {
790
-            $this->_host = strtolower($this->_host);
791
-        }
792
-
793
-        // Remove default port number for known schemes (RFC 3986, section 6.2.3)
794
-        if ('' === $this->_port
795
-            || $this->_port
796
-            && $this->_scheme
797
-            && $this->_port == getservbyname($this->_scheme, 'tcp')
798
-        ) {
799
-            $this->_port = false;
800
-        }
801
-
802
-        // Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1)
803
-        // Normalize percentage-encoded unreserved characters (section 6.2.2.2)
804
-        $fields = array(&$this->_userinfo, &$this->_host, &$this->_path,
805
-                        &$this->_query, &$this->_fragment);
806
-        foreach ($fields as &$field) {
807
-            if ($field !== false) {
808
-                $field = $this->_normalize("$field");
809
-            }
810
-        }
811
-        unset($field);
812
-
813
-        // Path segment normalization (RFC 3986, section 6.2.2.3)
814
-        $this->_path = self::removeDotSegments($this->_path);
815
-
816
-        // Scheme based normalization (RFC 3986, section 6.2.3)
817
-        if (false !== $this->_host && '' === $this->_path) {
818
-            $this->_path = '/';
819
-        }
820
-
821
-        // path should start with '/' if there is authority (section 3.3.)
822
-        if (strlen($this->getAuthority())
823
-            && strlen($this->_path)
824
-            && $this->_path[0] !== '/'
825
-        ) {
826
-            $this->_path = '/' . $this->_path;
827
-        }
828
-    }
829
-
830
-    /**
831
-     * Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1)
832
-     * Normalize percentage-encoded unreserved characters (section 6.2.2.2)
833
-     *
834
-     * @param string|array $mixed string or array of strings to normalize
835
-     *
836
-     * @return string|array
837
-     * @see normalize
838
-     * @see _normalizeCallback()
839
-     */
840
-    private function _normalize($mixed)
841
-    {
842
-        return preg_replace_callback(
843
-            '((?:%[0-9a-fA-Z]{2})+)', array($this, '_normalizeCallback'),
844
-            $mixed
845
-        );
846
-    }
847
-
848
-    /**
849
-     * Callback for _normalize() of %XX percentage-encodings
850
-     *
851
-     * @param array $matches as by preg_replace_callback
852
-     *
853
-     * @return string
854
-     * @see normalize
855
-     * @see _normalize
856
-     * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
857
-     */
858
-    private function _normalizeCallback($matches)
859
-    {
860
-        return self::urlencode(urldecode($matches[0]));
861
-    }
862
-
863
-    /**
864
-     * Returns whether this instance represents an absolute URL.
865
-     *
866
-     * @return bool
867
-     */
868
-    public function isAbsolute()
869
-    {
870
-        return (bool) $this->_scheme;
871
-    }
872
-
873
-    /**
874
-     * Returns an Net_URL2 instance representing an absolute URL relative to
875
-     * this URL.
876
-     *
877
-     * @param Net_URL2|string $reference relative URL
878
-     *
879
-     * @throws Exception
880
-     * @return $this
881
-     */
882
-    public function resolve($reference)
883
-    {
884
-        if (!$reference instanceof Net_URL2) {
885
-            $reference = new self($reference);
886
-        }
887
-        if (!$reference->_isFragmentOnly() && !$this->isAbsolute()) {
888
-            throw new Exception(
889
-                'Base-URL must be absolute if reference is not fragment-only'
890
-            );
891
-        }
892
-
893
-        // A non-strict parser may ignore a scheme in the reference if it is
894
-        // identical to the base URI's scheme.
895
-        if (!$this->getOption(self::OPTION_STRICT)
896
-            && $reference->_scheme == $this->_scheme
897
-        ) {
898
-            $reference->_scheme = false;
899
-        }
900
-
901
-        $target = new self('');
902
-        if ($reference->_scheme !== false) {
903
-            $target->_scheme = $reference->_scheme;
904
-            $target->setAuthority($reference->getAuthority());
905
-            $target->_path  = self::removeDotSegments($reference->_path);
906
-            $target->_query = $reference->_query;
907
-        } else {
908
-            $authority = $reference->getAuthority();
909
-            if ($authority !== false) {
910
-                $target->setAuthority($authority);
911
-                $target->_path  = self::removeDotSegments($reference->_path);
912
-                $target->_query = $reference->_query;
913
-            } else {
914
-                if ($reference->_path == '') {
915
-                    $target->_path = $this->_path;
916
-                    if ($reference->_query !== false) {
917
-                        $target->_query = $reference->_query;
918
-                    } else {
919
-                        $target->_query = $this->_query;
920
-                    }
921
-                } else {
922
-                    if (substr($reference->_path, 0, 1) == '/') {
923
-                        $target->_path = self::removeDotSegments($reference->_path);
924
-                    } else {
925
-                        // Merge paths (RFC 3986, section 5.2.3)
926
-                        if ($this->_host !== false && $this->_path == '') {
927
-                            $target->_path = '/' . $reference->_path;
928
-                        } else {
929
-                            $i = strrpos($this->_path, '/');
930
-                            if ($i !== false) {
931
-                                $target->_path = substr($this->_path, 0, $i + 1);
932
-                            }
933
-                            $target->_path .= $reference->_path;
934
-                        }
935
-                        $target->_path = self::removeDotSegments($target->_path);
936
-                    }
937
-                    $target->_query = $reference->_query;
938
-                }
939
-                $target->setAuthority($this->getAuthority());
940
-            }
941
-            $target->_scheme = $this->_scheme;
942
-        }
943
-
944
-        $target->_fragment = $reference->_fragment;
945
-
946
-        return $target;
947
-    }
948
-
949
-    /**
950
-     * URL is fragment-only
951
-     *
952
-     * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
953
-     * @return bool
954
-     */
955
-    private function _isFragmentOnly()
956
-    {
957
-        return (
958
-            $this->_fragment !== false
959
-            && $this->_query === false
960
-            && $this->_path === ''
961
-            && $this->_port === false
962
-            && $this->_host === false
963
-            && $this->_userinfo === false
964
-            && $this->_scheme === false
965
-        );
966
-    }
967
-
968
-    /**
969
-     * Removes dots as described in RFC 3986, section 5.2.4, e.g.
970
-     * "/foo/../bar/baz" => "/bar/baz"
971
-     *
972
-     * @param string $path a path
973
-     *
974
-     * @return string a path
975
-     */
976
-    public static function removeDotSegments($path)
977
-    {
978
-        $path = (string) $path;
979
-        $output = '';
980
-
981
-        // Make sure not to be trapped in an infinite loop due to a bug in this
982
-        // method
983
-        $loopLimit = 256;
984
-        $j = 0;
985
-        while ('' !== $path && $j++ < $loopLimit) {
986
-            if (substr($path, 0, 2) === './') {
987
-                // Step 2.A
988
-                $path = substr($path, 2);
989
-            } elseif (substr($path, 0, 3) === '../') {
990
-                // Step 2.A
991
-                $path = substr($path, 3);
992
-            } elseif (substr($path, 0, 3) === '/./' || $path === '/.') {
993
-                // Step 2.B
994
-                $path = '/' . substr($path, 3);
995
-            } elseif (substr($path, 0, 4) === '/../' || $path === '/..') {
996
-                // Step 2.C
997
-                $path   = '/' . substr($path, 4);
998
-                $i      = strrpos($output, '/');
999
-                $output = $i === false ? '' : substr($output, 0, $i);
1000
-            } elseif ($path === '.' || $path === '..') {
1001
-                // Step 2.D
1002
-                $path = '';
1003
-            } else {
1004
-                // Step 2.E
1005
-                $i = strpos($path, '/', $path[0] === '/');
1006
-                if ($i === false) {
1007
-                    $output .= $path;
1008
-                    $path = '';
1009
-                    break;
1010
-                }
1011
-                $output .= substr($path, 0, $i);
1012
-                $path = substr($path, $i);
1013
-            }
1014
-        }
1015
-
1016
-        if ($path !== '') {
1017
-            $message = sprintf(
1018
-                'Unable to remove dot segments; hit loop limit %d (left: %s)',
1019
-                $j, var_export($path, true)
1020
-            );
1021
-            trigger_error($message, E_USER_WARNING);
1022
-        }
1023
-
1024
-        return $output;
1025
-    }
1026
-
1027
-    /**
1028
-     * Percent-encodes all non-alphanumeric characters except these: _ . - ~
1029
-     * Similar to PHP's rawurlencode(), except that it also encodes ~ in PHP
1030
-     * 5.2.x and earlier.
1031
-     *
1032
-     * @param string $string string to encode
1033
-     *
1034
-     * @return string
1035
-     */
1036
-    public static function urlencode($string)
1037
-    {
1038
-        $encoded = rawurlencode($string);
1039
-
1040
-        // This is only necessary in PHP < 5.3.
1041
-        $encoded = str_replace('%7E', '~', $encoded);
1042
-        return $encoded;
1043
-    }
1044
-
1045
-    /**
1046
-     * Returns a Net_URL2 instance representing the canonical URL of the
1047
-     * currently executing PHP script.
1048
-     *
1049
-     * @throws Exception
1050
-     * @return string
1051
-     */
1052
-    public static function getCanonical()
1053
-    {
1054
-        if (!isset($_SERVER['REQUEST_METHOD'])) {
1055
-            // ALERT - no current URL
1056
-            throw new Exception('Script was not called through a webserver');
1057
-        }
1058
-
1059
-        // Begin with a relative URL
1060
-        $url = new self($_SERVER['PHP_SELF']);
1061
-        $url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
1062
-        $url->_host   = $_SERVER['SERVER_NAME'];
1063
-        $port = $_SERVER['SERVER_PORT'];
1064
-        if ($url->_scheme == 'http' && $port != 80
1065
-            || $url->_scheme == 'https' && $port != 443
1066
-        ) {
1067
-            $url->_port = $port;
1068
-        }
1069
-        return $url;
1070
-    }
1071
-
1072
-    /**
1073
-     * Returns the URL used to retrieve the current request.
1074
-     *
1075
-     * @return  string
1076
-     */
1077
-    public static function getRequestedURL()
1078
-    {
1079
-        return self::getRequested()->getUrl();
1080
-    }
1081
-
1082
-    /**
1083
-     * Returns a Net_URL2 instance representing the URL used to retrieve the
1084
-     * current request.
1085
-     *
1086
-     * @throws Exception
1087
-     * @return $this
1088
-     */
1089
-    public static function getRequested()
1090
-    {
1091
-        if (!isset($_SERVER['REQUEST_METHOD'])) {
1092
-            // ALERT - no current URL
1093
-            throw new Exception('Script was not called through a webserver');
1094
-        }
1095
-
1096
-        // Begin with a relative URL
1097
-        $url = new self($_SERVER['REQUEST_URI']);
1098
-        $url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
1099
-        // Set host and possibly port
1100
-        $url->setAuthority($_SERVER['HTTP_HOST']);
1101
-        return $url;
1102
-    }
1103
-
1104
-    /**
1105
-     * Returns the value of the specified option.
1106
-     *
1107
-     * @param string $optionName The name of the option to retrieve
1108
-     *
1109
-     * @return mixed
1110
-     */
1111
-    public function getOption($optionName)
1112
-    {
1113
-        return isset($this->_options[$optionName])
1114
-            ? $this->_options[$optionName] : false;
1115
-    }
1116
-
1117
-    /**
1118
-     * A simple version of http_build_query in userland. The encoded string is
1119
-     * percentage encoded according to RFC 3986.
1120
-     *
1121
-     * @param array  $data      An array, which has to be converted into
1122
-     *                          QUERY_STRING. Anything is possible.
1123
-     * @param string $separator Separator {@link self::OPTION_SEPARATOR_OUTPUT}
1124
-     * @param string $key       For stacked values (arrays in an array).
1125
-     *
1126
-     * @return string
1127
-     */
1128
-    protected function buildQuery(array $data, $separator, $key = null)
1129
-    {
1130
-        $query = array();
1131
-        $drop_names = (
1132
-            $this->_options[self::OPTION_DROP_SEQUENCE] === true
1133
-            && array_keys($data) === array_keys(array_values($data))
1134
-        );
1135
-        foreach ($data as $name => $value) {
1136
-            if ($this->getOption(self::OPTION_ENCODE_KEYS) === true) {
1137
-                $name = rawurlencode($name);
1138
-            }
1139
-            if ($key !== null) {
1140
-                if ($this->getOption(self::OPTION_USE_BRACKETS) === true) {
1141
-                    $drop_names && $name = '';
1142
-                    $name = $key . '[' . $name . ']';
1143
-                } else {
1144
-                    $name = $key;
1145
-                }
1146
-            }
1147
-            if (is_array($value)) {
1148
-                $query[] = $this->buildQuery($value, $separator, $name);
1149
-            } else {
1150
-                $query[] = $name . '=' . rawurlencode($value);
1151
-            }
1152
-        }
1153
-        return implode($separator, $query);
1154
-    }
1155
-
1156
-    /**
1157
-     * This method uses a regex to parse the url into the designated parts.
1158
-     *
1159
-     * @param string $url URL
1160
-     *
1161
-     * @return void
1162
-     * @uses   self::$_scheme, self::setAuthority(), self::$_path, self::$_query,
1163
-     *         self::$_fragment
1164
-     * @see    __construct
1165
-     */
1166
-    protected function parseUrl($url)
1167
-    {
1168
-        // The regular expression is copied verbatim from RFC 3986, appendix B.
1169
-        // The expression does not validate the URL but matches any string.
1170
-        preg_match(
1171
-            '(^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?)',
1172
-            $url, $matches
1173
-        );
1174
-
1175
-        // "path" is always present (possibly as an empty string); the rest
1176
-        // are optional.
1177
-        $this->_scheme   = !empty($matches[1]) ? $matches[2] : false;
1178
-        $this->setAuthority(!empty($matches[3]) ? $matches[4] : false);
1179
-        $this->_path     = $this->_encodeData($matches[5]);
1180
-        $this->_query    = !empty($matches[6])
1181
-                           ? $this->_encodeData($matches[7])
1182
-                           : false
1183
-            ;
1184
-        $this->_fragment = !empty($matches[8]) ? $matches[9] : false;
1185
-    }
1186
-
1187
-    /**
1188
-     * Encode characters that might have been forgotten to encode when passing
1189
-     * in an URL. Applied onto Userinfo, Path and Query.
1190
-     *
1191
-     * @param string $url URL
1192
-     *
1193
-     * @return string
1194
-     * @see parseUrl
1195
-     * @see setAuthority
1196
-     * @link https://pear.php.net/bugs/bug.php?id=20425
1197
-     */
1198
-    private function _encodeData($url)
1199
-    {
1200
-        return preg_replace_callback(
1201
-            '([\x-\x20\x22\x3C\x3E\x7F-\xFF]+)',
1202
-            array($this, '_encodeCallback'), $url
1203
-        );
1204
-    }
1205
-
1206
-    /**
1207
-     * callback for encoding character data
1208
-     *
1209
-     * @param array $matches Matches
1210
-     *
1211
-     * @return string
1212
-     * @see _encodeData
1213
-     * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
1214
-     */
1215
-    private function _encodeCallback(array $matches)
1216
-    {
1217
-        return rawurlencode($matches[0]);
1218
-    }
59
+	/**
60
+	 * Do strict parsing in resolve() (see RFC 3986, section 5.2.2). Default
61
+	 * is true.
62
+	 */
63
+	const OPTION_STRICT = 'strict';
64
+
65
+	/**
66
+	 * Represent arrays in query using PHP's [] notation. Default is true.
67
+	 */
68
+	const OPTION_USE_BRACKETS = 'use_brackets';
69
+
70
+	/**
71
+	 * Drop zero-based integer sequences in query using PHP's [] notation. Default
72
+	 * is true.
73
+	 */
74
+	const OPTION_DROP_SEQUENCE = 'drop_sequence';
75
+
76
+	/**
77
+	 * URL-encode query variable keys. Default is true.
78
+	 */
79
+	const OPTION_ENCODE_KEYS = 'encode_keys';
80
+
81
+	/**
82
+	 * Query variable separators when parsing the query string. Every character
83
+	 * is considered a separator. Default is "&".
84
+	 */
85
+	const OPTION_SEPARATOR_INPUT = 'input_separator';
86
+
87
+	/**
88
+	 * Query variable separator used when generating the query string. Default
89
+	 * is "&".
90
+	 */
91
+	const OPTION_SEPARATOR_OUTPUT = 'output_separator';
92
+
93
+	/**
94
+	 * Default options corresponds to how PHP handles $_GET.
95
+	 */
96
+	private $_options = array(
97
+		self::OPTION_STRICT           => true,
98
+		self::OPTION_USE_BRACKETS     => true,
99
+		self::OPTION_DROP_SEQUENCE    => true,
100
+		self::OPTION_ENCODE_KEYS      => true,
101
+		self::OPTION_SEPARATOR_INPUT  => '&',
102
+		self::OPTION_SEPARATOR_OUTPUT => '&',
103
+		);
104
+
105
+	/**
106
+	 * @var  string|bool
107
+	 */
108
+	private $_scheme = false;
109
+
110
+	/**
111
+	 * @var  string|bool
112
+	 */
113
+	private $_userinfo = false;
114
+
115
+	/**
116
+	 * @var  string|bool
117
+	 */
118
+	private $_host = false;
119
+
120
+	/**
121
+	 * @var  string|bool
122
+	 */
123
+	private $_port = false;
124
+
125
+	/**
126
+	 * @var  string
127
+	 */
128
+	private $_path = '';
129
+
130
+	/**
131
+	 * @var  string|bool
132
+	 */
133
+	private $_query = false;
134
+
135
+	/**
136
+	 * @var  string|bool
137
+	 */
138
+	private $_fragment = false;
139
+
140
+	/**
141
+	 * Constructor.
142
+	 *
143
+	 * @param string $url     an absolute or relative URL
144
+	 * @param array  $options an array of OPTION_xxx constants
145
+	 *
146
+	 * @uses   self::parseUrl()
147
+	 */
148
+	public function __construct($url, array $options = array())
149
+	{
150
+		foreach ($options as $optionName => $value) {
151
+			if (array_key_exists($optionName, $this->_options)) {
152
+				$this->_options[$optionName] = $value;
153
+			}
154
+		}
155
+
156
+		$this->parseUrl($url);
157
+	}
158
+
159
+	/**
160
+	 * Magic Setter.
161
+	 *
162
+	 * This method will magically set the value of a private variable ($var)
163
+	 * with the value passed as the args
164
+	 *
165
+	 * @param string $var The private variable to set.
166
+	 * @param mixed  $arg An argument of any type.
167
+	 *
168
+	 * @return void
169
+	 */
170
+	public function __set($var, $arg)
171
+	{
172
+		$method = 'set' . $var;
173
+		if (method_exists($this, $method)) {
174
+			$this->$method($arg);
175
+		}
176
+	}
177
+
178
+	/**
179
+	 * Magic Getter.
180
+	 *
181
+	 * This is the magic get method to retrieve the private variable
182
+	 * that was set by either __set() or it's setter...
183
+	 *
184
+	 * @param string $var The property name to retrieve.
185
+	 *
186
+	 * @return mixed  $this->$var Either a boolean false if the
187
+	 *                            property is not set or the value
188
+	 *                            of the private property.
189
+	 */
190
+	public function __get($var)
191
+	{
192
+		$method = 'get' . $var;
193
+		if (method_exists($this, $method)) {
194
+			return $this->$method();
195
+		}
196
+
197
+		return false;
198
+	}
199
+
200
+	/**
201
+	 * Returns the scheme, e.g. "http" or "urn", or false if there is no
202
+	 * scheme specified, i.e. if this is a relative URL.
203
+	 *
204
+	 * @return string|bool
205
+	 */
206
+	public function getScheme()
207
+	{
208
+		return $this->_scheme;
209
+	}
210
+
211
+	/**
212
+	 * Sets the scheme, e.g. "http" or "urn". Specify false if there is no
213
+	 * scheme specified, i.e. if this is a relative URL.
214
+	 *
215
+	 * @param string|bool $scheme e.g. "http" or "urn", or false if there is no
216
+	 *                            scheme specified, i.e. if this is a relative
217
+	 *                            URL
218
+	 *
219
+	 * @return $this
220
+	 * @see    getScheme
221
+	 */
222
+	public function setScheme($scheme)
223
+	{
224
+		$this->_scheme = $scheme;
225
+		return $this;
226
+	}
227
+
228
+	/**
229
+	 * Returns the user part of the userinfo part (the part preceding the first
230
+	 *  ":"), or false if there is no userinfo part.
231
+	 *
232
+	 * @return string|bool
233
+	 */
234
+	public function getUser()
235
+	{
236
+		return $this->_userinfo !== false
237
+			? preg_replace('(:.*$)', '', $this->_userinfo)
238
+			: false;
239
+	}
240
+
241
+	/**
242
+	 * Returns the password part of the userinfo part (the part after the first
243
+	 *  ":"), or false if there is no userinfo part (i.e. the URL does not
244
+	 * contain "@" in front of the hostname) or the userinfo part does not
245
+	 * contain ":".
246
+	 *
247
+	 * @return string|bool
248
+	 */
249
+	public function getPassword()
250
+	{
251
+		return $this->_userinfo !== false
252
+			? substr(strstr($this->_userinfo, ':'), 1)
253
+			: false;
254
+	}
255
+
256
+	/**
257
+	 * Returns the userinfo part, or false if there is none, i.e. if the
258
+	 * authority part does not contain "@".
259
+	 *
260
+	 * @return string|bool
261
+	 */
262
+	public function getUserinfo()
263
+	{
264
+		return $this->_userinfo;
265
+	}
266
+
267
+	/**
268
+	 * Sets the userinfo part. If two arguments are passed, they are combined
269
+	 * in the userinfo part as username ":" password.
270
+	 *
271
+	 * @param string|bool $userinfo userinfo or username
272
+	 * @param string|bool $password optional password, or false
273
+	 *
274
+	 * @return $this
275
+	 */
276
+	public function setUserinfo($userinfo, $password = false)
277
+	{
278
+		if ($password !== false) {
279
+			$userinfo .= ':' . $password;
280
+		}
281
+
282
+		if ($userinfo !== false) {
283
+			$userinfo = $this->_encodeData($userinfo);
284
+		}
285
+
286
+		$this->_userinfo = $userinfo;
287
+		return $this;
288
+	}
289
+
290
+	/**
291
+	 * Returns the host part, or false if there is no authority part, e.g.
292
+	 * relative URLs.
293
+	 *
294
+	 * @return string|bool a hostname, an IP address, or false
295
+	 */
296
+	public function getHost()
297
+	{
298
+		return $this->_host;
299
+	}
300
+
301
+	/**
302
+	 * Sets the host part. Specify false if there is no authority part, e.g.
303
+	 * relative URLs.
304
+	 *
305
+	 * @param string|bool $host a hostname, an IP address, or false
306
+	 *
307
+	 * @return $this
308
+	 */
309
+	public function setHost($host)
310
+	{
311
+		$this->_host = $host;
312
+		return $this;
313
+	}
314
+
315
+	/**
316
+	 * Returns the port number, or false if there is no port number specified,
317
+	 * i.e. if the default port is to be used.
318
+	 *
319
+	 * @return string|bool
320
+	 */
321
+	public function getPort()
322
+	{
323
+		return $this->_port;
324
+	}
325
+
326
+	/**
327
+	 * Sets the port number. Specify false if there is no port number specified,
328
+	 * i.e. if the default port is to be used.
329
+	 *
330
+	 * @param string|bool $port a port number, or false
331
+	 *
332
+	 * @return $this
333
+	 */
334
+	public function setPort($port)
335
+	{
336
+		$this->_port = $port;
337
+		return $this;
338
+	}
339
+
340
+	/**
341
+	 * Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or
342
+	 * false if there is no authority.
343
+	 *
344
+	 * @return string|bool
345
+	 */
346
+	public function getAuthority()
347
+	{
348
+		if (false === $this->_host) {
349
+			return false;
350
+		}
351
+
352
+		$authority = '';
353
+
354
+		if (strlen($this->_userinfo)) {
355
+			$authority .= $this->_userinfo . '@';
356
+		}
357
+
358
+		$authority .= $this->_host;
359
+
360
+		if ($this->_port !== false) {
361
+			$authority .= ':' . $this->_port;
362
+		}
363
+
364
+		return $authority;
365
+	}
366
+
367
+	/**
368
+	 * Sets the authority part, i.e. [ userinfo "@" ] host [ ":" port ]. Specify
369
+	 * false if there is no authority.
370
+	 *
371
+	 * @param string|bool $authority a hostname or an IP address, possibly
372
+	 *                                with userinfo prefixed and port number
373
+	 *                                appended, e.g. "foo:[email protected]:81".
374
+	 *
375
+	 * @return $this
376
+	 */
377
+	public function setAuthority($authority)
378
+	{
379
+		$this->_userinfo = false;
380
+		$this->_host     = false;
381
+		$this->_port     = false;
382
+
383
+		if ('' === $authority) {
384
+			$this->_host = $authority;
385
+			return $this;
386
+		}
387
+
388
+		if (!preg_match('(^(([^\@]*)\@)?(.+?)(:(\d*))?$)', $authority, $matches)) {
389
+			return $this;
390
+		}
391
+
392
+		if ($matches[1]) {
393
+			$this->_userinfo = $this->_encodeData($matches[2]);
394
+		}
395
+
396
+		$this->_host = $matches[3];
397
+
398
+		if (isset($matches[5]) && strlen($matches[5])) {
399
+			$this->_port = $matches[5];
400
+		}
401
+		return $this;
402
+	}
403
+
404
+	/**
405
+	 * Returns the path part (possibly an empty string).
406
+	 *
407
+	 * @return string
408
+	 */
409
+	public function getPath()
410
+	{
411
+		return $this->_path;
412
+	}
413
+
414
+	/**
415
+	 * Sets the path part (possibly an empty string).
416
+	 *
417
+	 * @param string $path a path
418
+	 *
419
+	 * @return $this
420
+	 */
421
+	public function setPath($path)
422
+	{
423
+		$this->_path = $path;
424
+		return $this;
425
+	}
426
+
427
+	/**
428
+	 * Returns the query string (excluding the leading "?"), or false if "?"
429
+	 * is not present in the URL.
430
+	 *
431
+	 * @return  string|bool
432
+	 * @see     getQueryVariables
433
+	 */
434
+	public function getQuery()
435
+	{
436
+		return $this->_query;
437
+	}
438
+
439
+	/**
440
+	 * Sets the query string (excluding the leading "?"). Specify false if "?"
441
+	 * is not present in the URL.
442
+	 *
443
+	 * @param string|bool $query a query string, e.g. "foo=1&bar=2"
444
+	 *
445
+	 * @return $this
446
+	 * @see    setQueryVariables
447
+	 */
448
+	public function setQuery($query)
449
+	{
450
+		$this->_query = $query;
451
+		return $this;
452
+	}
453
+
454
+	/**
455
+	 * Returns the fragment name, or false if "#" is not present in the URL.
456
+	 *
457
+	 * @return string|bool
458
+	 */
459
+	public function getFragment()
460
+	{
461
+		return $this->_fragment;
462
+	}
463
+
464
+	/**
465
+	 * Sets the fragment name. Specify false if "#" is not present in the URL.
466
+	 *
467
+	 * @param string|bool $fragment a fragment excluding the leading "#", or
468
+	 *                              false
469
+	 *
470
+	 * @return $this
471
+	 */
472
+	public function setFragment($fragment)
473
+	{
474
+		$this->_fragment = $fragment;
475
+		return $this;
476
+	}
477
+
478
+	/**
479
+	 * Returns the query string like an array as the variables would appear in
480
+	 * $_GET in a PHP script. If the URL does not contain a "?", an empty array
481
+	 * is returned.
482
+	 *
483
+	 * @return array
484
+	 */
485
+	public function getQueryVariables()
486
+	{
487
+		$separator   = $this->getOption(self::OPTION_SEPARATOR_INPUT);
488
+		$encodeKeys  = $this->getOption(self::OPTION_ENCODE_KEYS);
489
+		$useBrackets = $this->getOption(self::OPTION_USE_BRACKETS);
490
+
491
+		$return  = array();
492
+
493
+		for ($part = strtok($this->_query, $separator);
494
+			strlen($part);
495
+			$part = strtok($separator)
496
+		) {
497
+			list($key, $value) = explode('=', $part, 2) + array(1 => '');
498
+
499
+			if ($encodeKeys) {
500
+				$key = rawurldecode($key);
501
+			}
502
+			$value = rawurldecode($value);
503
+
504
+			if ($useBrackets) {
505
+				$return = $this->_queryArrayByKey($key, $value, $return);
506
+			} else {
507
+				if (isset($return[$key])) {
508
+					$return[$key]  = (array) $return[$key];
509
+					$return[$key][] = $value;
510
+				} else {
511
+					$return[$key] = $value;
512
+				}
513
+			}
514
+		}
515
+
516
+		return $return;
517
+	}
518
+
519
+	/**
520
+	 * Parse a single query key=value pair into an existing php array
521
+	 *
522
+	 * @param string $key   query-key
523
+	 * @param string $value query-value
524
+	 * @param array  $array of existing query variables (if any)
525
+	 *
526
+	 * @return mixed
527
+	 */
528
+	private function _queryArrayByKey($key, $value, array $array = array())
529
+	{
530
+		if (!strlen($key)) {
531
+			return $array;
532
+		}
533
+
534
+		$offset = $this->_queryKeyBracketOffset($key);
535
+		if ($offset === false) {
536
+			$name = $key;
537
+		} else {
538
+			$name = substr($key, 0, $offset);
539
+		}
540
+
541
+		if (!strlen($name)) {
542
+			return $array;
543
+		}
544
+
545
+		if (!$offset) {
546
+			// named value
547
+			$array[$name] = $value;
548
+		} else {
549
+			// array
550
+			$brackets = substr($key, $offset);
551
+			if (!isset($array[$name])) {
552
+				$array[$name] = null;
553
+			}
554
+			$array[$name] = $this->_queryArrayByBrackets(
555
+				$brackets, $value, $array[$name]
556
+			);
557
+		}
558
+
559
+		return $array;
560
+	}
561
+
562
+	/**
563
+	 * Parse a key-buffer to place value in array
564
+	 *
565
+	 * @param string $buffer to consume all keys from
566
+	 * @param string $value  to be set/add
567
+	 * @param array  $array  to traverse and set/add value in
568
+	 *
569
+	 * @throws Exception
570
+	 * @return array
571
+	 */
572
+	private function _queryArrayByBrackets($buffer, $value, array $array = null)
573
+	{
574
+		$entry = &$array;
575
+
576
+		for ($iteration = 0; strlen($buffer); $iteration++) {
577
+			$open = $this->_queryKeyBracketOffset($buffer);
578
+			if ($open !== 0) {
579
+				// Opening bracket [ must exist at offset 0, if not, there is
580
+				// no bracket to parse and the value dropped.
581
+				// if this happens in the first iteration, this is flawed, see
582
+				// as well the second exception below.
583
+				if ($iteration) {
584
+					break;
585
+				}
586
+				// @codeCoverageIgnoreStart
587
+				throw new Exception(
588
+					'Net_URL2 Internal Error: '. __METHOD__ .'(): ' .
589
+					'Opening bracket [ must exist at offset 0'
590
+				);
591
+				// @codeCoverageIgnoreEnd
592
+			}
593
+
594
+			$close = strpos($buffer, ']', 1);
595
+			if (!$close) {
596
+				// this error condition should never be reached as this is a
597
+				// private method and bracket pairs are checked beforehand.
598
+				// See as well the first exception for the opening bracket.
599
+				// @codeCoverageIgnoreStart
600
+				throw new Exception(
601
+					'Net_URL2 Internal Error: '. __METHOD__ .'(): ' .
602
+					'Closing bracket ] must exist, not found'
603
+				);
604
+				// @codeCoverageIgnoreEnd
605
+			}
606
+
607
+			$index = substr($buffer, 1, $close - 1);
608
+			if (strlen($index)) {
609
+				$entry = &$entry[$index];
610
+			} else {
611
+				if (!is_array($entry)) {
612
+					$entry = array();
613
+				}
614
+				$entry[] = &$new;
615
+				$entry = &$new;
616
+				unset($new);
617
+			}
618
+			$buffer = substr($buffer, $close + 1);
619
+		}
620
+
621
+		$entry = $value;
622
+
623
+		return $array;
624
+	}
625
+
626
+	/**
627
+	 * Query-key has brackets ("...[]")
628
+	 *
629
+	 * @param string $key query-key
630
+	 *
631
+	 * @return bool|int offset of opening bracket, false if no brackets
632
+	 */
633
+	private function _queryKeyBracketOffset($key)
634
+	{
635
+		if (false !== $open = strpos($key, '[')
636
+			and false === strpos($key, ']', $open + 1)
637
+		) {
638
+			$open = false;
639
+		}
640
+
641
+		return $open;
642
+	}
643
+
644
+	/**
645
+	 * Sets the query string to the specified variable in the query string.
646
+	 *
647
+	 * @param array $array (name => value) array
648
+	 *
649
+	 * @return $this
650
+	 */
651
+	public function setQueryVariables(array $array)
652
+	{
653
+		if (!$array) {
654
+			$this->_query = false;
655
+		} else {
656
+			$this->_query = $this->buildQuery(
657
+				$array,
658
+				$this->getOption(self::OPTION_SEPARATOR_OUTPUT)
659
+			);
660
+		}
661
+		return $this;
662
+	}
663
+
664
+	/**
665
+	 * Sets the specified variable in the query string.
666
+	 *
667
+	 * @param string $name  variable name
668
+	 * @param mixed  $value variable value
669
+	 *
670
+	 * @return $this
671
+	 */
672
+	public function setQueryVariable($name, $value)
673
+	{
674
+		$array = $this->getQueryVariables();
675
+		$array[$name] = $value;
676
+		$this->setQueryVariables($array);
677
+		return $this;
678
+	}
679
+
680
+	/**
681
+	 * Removes the specified variable from the query string.
682
+	 *
683
+	 * @param string $name a query string variable, e.g. "foo" in "?foo=1"
684
+	 *
685
+	 * @return void
686
+	 */
687
+	public function unsetQueryVariable($name)
688
+	{
689
+		$array = $this->getQueryVariables();
690
+		unset($array[$name]);
691
+		$this->setQueryVariables($array);
692
+	}
693
+
694
+	/**
695
+	 * Returns a string representation of this URL.
696
+	 *
697
+	 * @return string
698
+	 */
699
+	public function getURL()
700
+	{
701
+		// See RFC 3986, section 5.3
702
+		$url = '';
703
+
704
+		if ($this->_scheme !== false) {
705
+			$url .= $this->_scheme . ':';
706
+		}
707
+
708
+		$authority = $this->getAuthority();
709
+		if ($authority === false && strtolower($this->_scheme) === 'file') {
710
+			$authority = '';
711
+		}
712
+
713
+		$url .= $this->_buildAuthorityAndPath($authority, $this->_path);
714
+
715
+		if ($this->_query !== false) {
716
+			$url .= '?' . $this->_query;
717
+		}
718
+
719
+		if ($this->_fragment !== false) {
720
+			$url .= '#' . $this->_fragment;
721
+		}
722
+
723
+		return $url;
724
+	}
725
+
726
+	/**
727
+	 * Put authority and path together, wrapping authority
728
+	 * into proper separators/terminators.
729
+	 *
730
+	 * @param string|bool $authority authority
731
+	 * @param string      $path      path
732
+	 *
733
+	 * @return string
734
+	 */
735
+	private function _buildAuthorityAndPath($authority, $path)
736
+	{
737
+		if ($authority === false) {
738
+			return $path;
739
+		}
740
+
741
+		$terminator = ($path !== '' && $path[0] !== '/') ? '/' : '';
742
+
743
+		return '//' . $authority . $terminator . $path;
744
+	}
745
+
746
+	/**
747
+	 * Returns a string representation of this URL.
748
+	 *
749
+	 * @return string
750
+	 * @link https://php.net/language.oop5.magic#object.tostring
751
+	 */
752
+	public function __toString()
753
+	{
754
+		return $this->getURL();
755
+	}
756
+
757
+	/**
758
+	 * Returns a normalized string representation of this URL. This is useful
759
+	 * for comparison of URLs.
760
+	 *
761
+	 * @return string
762
+	 */
763
+	public function getNormalizedURL()
764
+	{
765
+		$url = clone $this;
766
+		$url->normalize();
767
+		return $url->getUrl();
768
+	}
769
+
770
+	/**
771
+	 * Normalizes the URL
772
+	 *
773
+	 * See RFC 3986, Section 6.  Normalization and Comparison
774
+	 *
775
+	 * @link https://tools.ietf.org/html/rfc3986#section-6
776
+	 *
777
+	 * @return void
778
+	 */
779
+	public function normalize()
780
+	{
781
+		// See RFC 3986, section 6
782
+
783
+		// Scheme is case-insensitive
784
+		if ($this->_scheme) {
785
+			$this->_scheme = strtolower($this->_scheme);
786
+		}
787
+
788
+		// Hostname is case-insensitive
789
+		if ($this->_host) {
790
+			$this->_host = strtolower($this->_host);
791
+		}
792
+
793
+		// Remove default port number for known schemes (RFC 3986, section 6.2.3)
794
+		if ('' === $this->_port
795
+			|| $this->_port
796
+			&& $this->_scheme
797
+			&& $this->_port == getservbyname($this->_scheme, 'tcp')
798
+		) {
799
+			$this->_port = false;
800
+		}
801
+
802
+		// Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1)
803
+		// Normalize percentage-encoded unreserved characters (section 6.2.2.2)
804
+		$fields = array(&$this->_userinfo, &$this->_host, &$this->_path,
805
+						&$this->_query, &$this->_fragment);
806
+		foreach ($fields as &$field) {
807
+			if ($field !== false) {
808
+				$field = $this->_normalize("$field");
809
+			}
810
+		}
811
+		unset($field);
812
+
813
+		// Path segment normalization (RFC 3986, section 6.2.2.3)
814
+		$this->_path = self::removeDotSegments($this->_path);
815
+
816
+		// Scheme based normalization (RFC 3986, section 6.2.3)
817
+		if (false !== $this->_host && '' === $this->_path) {
818
+			$this->_path = '/';
819
+		}
820
+
821
+		// path should start with '/' if there is authority (section 3.3.)
822
+		if (strlen($this->getAuthority())
823
+			&& strlen($this->_path)
824
+			&& $this->_path[0] !== '/'
825
+		) {
826
+			$this->_path = '/' . $this->_path;
827
+		}
828
+	}
829
+
830
+	/**
831
+	 * Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1)
832
+	 * Normalize percentage-encoded unreserved characters (section 6.2.2.2)
833
+	 *
834
+	 * @param string|array $mixed string or array of strings to normalize
835
+	 *
836
+	 * @return string|array
837
+	 * @see normalize
838
+	 * @see _normalizeCallback()
839
+	 */
840
+	private function _normalize($mixed)
841
+	{
842
+		return preg_replace_callback(
843
+			'((?:%[0-9a-fA-Z]{2})+)', array($this, '_normalizeCallback'),
844
+			$mixed
845
+		);
846
+	}
847
+
848
+	/**
849
+	 * Callback for _normalize() of %XX percentage-encodings
850
+	 *
851
+	 * @param array $matches as by preg_replace_callback
852
+	 *
853
+	 * @return string
854
+	 * @see normalize
855
+	 * @see _normalize
856
+	 * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
857
+	 */
858
+	private function _normalizeCallback($matches)
859
+	{
860
+		return self::urlencode(urldecode($matches[0]));
861
+	}
862
+
863
+	/**
864
+	 * Returns whether this instance represents an absolute URL.
865
+	 *
866
+	 * @return bool
867
+	 */
868
+	public function isAbsolute()
869
+	{
870
+		return (bool) $this->_scheme;
871
+	}
872
+
873
+	/**
874
+	 * Returns an Net_URL2 instance representing an absolute URL relative to
875
+	 * this URL.
876
+	 *
877
+	 * @param Net_URL2|string $reference relative URL
878
+	 *
879
+	 * @throws Exception
880
+	 * @return $this
881
+	 */
882
+	public function resolve($reference)
883
+	{
884
+		if (!$reference instanceof Net_URL2) {
885
+			$reference = new self($reference);
886
+		}
887
+		if (!$reference->_isFragmentOnly() && !$this->isAbsolute()) {
888
+			throw new Exception(
889
+				'Base-URL must be absolute if reference is not fragment-only'
890
+			);
891
+		}
892
+
893
+		// A non-strict parser may ignore a scheme in the reference if it is
894
+		// identical to the base URI's scheme.
895
+		if (!$this->getOption(self::OPTION_STRICT)
896
+			&& $reference->_scheme == $this->_scheme
897
+		) {
898
+			$reference->_scheme = false;
899
+		}
900
+
901
+		$target = new self('');
902
+		if ($reference->_scheme !== false) {
903
+			$target->_scheme = $reference->_scheme;
904
+			$target->setAuthority($reference->getAuthority());
905
+			$target->_path  = self::removeDotSegments($reference->_path);
906
+			$target->_query = $reference->_query;
907
+		} else {
908
+			$authority = $reference->getAuthority();
909
+			if ($authority !== false) {
910
+				$target->setAuthority($authority);
911
+				$target->_path  = self::removeDotSegments($reference->_path);
912
+				$target->_query = $reference->_query;
913
+			} else {
914
+				if ($reference->_path == '') {
915
+					$target->_path = $this->_path;
916
+					if ($reference->_query !== false) {
917
+						$target->_query = $reference->_query;
918
+					} else {
919
+						$target->_query = $this->_query;
920
+					}
921
+				} else {
922
+					if (substr($reference->_path, 0, 1) == '/') {
923
+						$target->_path = self::removeDotSegments($reference->_path);
924
+					} else {
925
+						// Merge paths (RFC 3986, section 5.2.3)
926
+						if ($this->_host !== false && $this->_path == '') {
927
+							$target->_path = '/' . $reference->_path;
928
+						} else {
929
+							$i = strrpos($this->_path, '/');
930
+							if ($i !== false) {
931
+								$target->_path = substr($this->_path, 0, $i + 1);
932
+							}
933
+							$target->_path .= $reference->_path;
934
+						}
935
+						$target->_path = self::removeDotSegments($target->_path);
936
+					}
937
+					$target->_query = $reference->_query;
938
+				}
939
+				$target->setAuthority($this->getAuthority());
940
+			}
941
+			$target->_scheme = $this->_scheme;
942
+		}
943
+
944
+		$target->_fragment = $reference->_fragment;
945
+
946
+		return $target;
947
+	}
948
+
949
+	/**
950
+	 * URL is fragment-only
951
+	 *
952
+	 * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
953
+	 * @return bool
954
+	 */
955
+	private function _isFragmentOnly()
956
+	{
957
+		return (
958
+			$this->_fragment !== false
959
+			&& $this->_query === false
960
+			&& $this->_path === ''
961
+			&& $this->_port === false
962
+			&& $this->_host === false
963
+			&& $this->_userinfo === false
964
+			&& $this->_scheme === false
965
+		);
966
+	}
967
+
968
+	/**
969
+	 * Removes dots as described in RFC 3986, section 5.2.4, e.g.
970
+	 * "/foo/../bar/baz" => "/bar/baz"
971
+	 *
972
+	 * @param string $path a path
973
+	 *
974
+	 * @return string a path
975
+	 */
976
+	public static function removeDotSegments($path)
977
+	{
978
+		$path = (string) $path;
979
+		$output = '';
980
+
981
+		// Make sure not to be trapped in an infinite loop due to a bug in this
982
+		// method
983
+		$loopLimit = 256;
984
+		$j = 0;
985
+		while ('' !== $path && $j++ < $loopLimit) {
986
+			if (substr($path, 0, 2) === './') {
987
+				// Step 2.A
988
+				$path = substr($path, 2);
989
+			} elseif (substr($path, 0, 3) === '../') {
990
+				// Step 2.A
991
+				$path = substr($path, 3);
992
+			} elseif (substr($path, 0, 3) === '/./' || $path === '/.') {
993
+				// Step 2.B
994
+				$path = '/' . substr($path, 3);
995
+			} elseif (substr($path, 0, 4) === '/../' || $path === '/..') {
996
+				// Step 2.C
997
+				$path   = '/' . substr($path, 4);
998
+				$i      = strrpos($output, '/');
999
+				$output = $i === false ? '' : substr($output, 0, $i);
1000
+			} elseif ($path === '.' || $path === '..') {
1001
+				// Step 2.D
1002
+				$path = '';
1003
+			} else {
1004
+				// Step 2.E
1005
+				$i = strpos($path, '/', $path[0] === '/');
1006
+				if ($i === false) {
1007
+					$output .= $path;
1008
+					$path = '';
1009
+					break;
1010
+				}
1011
+				$output .= substr($path, 0, $i);
1012
+				$path = substr($path, $i);
1013
+			}
1014
+		}
1015
+
1016
+		if ($path !== '') {
1017
+			$message = sprintf(
1018
+				'Unable to remove dot segments; hit loop limit %d (left: %s)',
1019
+				$j, var_export($path, true)
1020
+			);
1021
+			trigger_error($message, E_USER_WARNING);
1022
+		}
1023
+
1024
+		return $output;
1025
+	}
1026
+
1027
+	/**
1028
+	 * Percent-encodes all non-alphanumeric characters except these: _ . - ~
1029
+	 * Similar to PHP's rawurlencode(), except that it also encodes ~ in PHP
1030
+	 * 5.2.x and earlier.
1031
+	 *
1032
+	 * @param string $string string to encode
1033
+	 *
1034
+	 * @return string
1035
+	 */
1036
+	public static function urlencode($string)
1037
+	{
1038
+		$encoded = rawurlencode($string);
1039
+
1040
+		// This is only necessary in PHP < 5.3.
1041
+		$encoded = str_replace('%7E', '~', $encoded);
1042
+		return $encoded;
1043
+	}
1044
+
1045
+	/**
1046
+	 * Returns a Net_URL2 instance representing the canonical URL of the
1047
+	 * currently executing PHP script.
1048
+	 *
1049
+	 * @throws Exception
1050
+	 * @return string
1051
+	 */
1052
+	public static function getCanonical()
1053
+	{
1054
+		if (!isset($_SERVER['REQUEST_METHOD'])) {
1055
+			// ALERT - no current URL
1056
+			throw new Exception('Script was not called through a webserver');
1057
+		}
1058
+
1059
+		// Begin with a relative URL
1060
+		$url = new self($_SERVER['PHP_SELF']);
1061
+		$url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
1062
+		$url->_host   = $_SERVER['SERVER_NAME'];
1063
+		$port = $_SERVER['SERVER_PORT'];
1064
+		if ($url->_scheme == 'http' && $port != 80
1065
+			|| $url->_scheme == 'https' && $port != 443
1066
+		) {
1067
+			$url->_port = $port;
1068
+		}
1069
+		return $url;
1070
+	}
1071
+
1072
+	/**
1073
+	 * Returns the URL used to retrieve the current request.
1074
+	 *
1075
+	 * @return  string
1076
+	 */
1077
+	public static function getRequestedURL()
1078
+	{
1079
+		return self::getRequested()->getUrl();
1080
+	}
1081
+
1082
+	/**
1083
+	 * Returns a Net_URL2 instance representing the URL used to retrieve the
1084
+	 * current request.
1085
+	 *
1086
+	 * @throws Exception
1087
+	 * @return $this
1088
+	 */
1089
+	public static function getRequested()
1090
+	{
1091
+		if (!isset($_SERVER['REQUEST_METHOD'])) {
1092
+			// ALERT - no current URL
1093
+			throw new Exception('Script was not called through a webserver');
1094
+		}
1095
+
1096
+		// Begin with a relative URL
1097
+		$url = new self($_SERVER['REQUEST_URI']);
1098
+		$url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
1099
+		// Set host and possibly port
1100
+		$url->setAuthority($_SERVER['HTTP_HOST']);
1101
+		return $url;
1102
+	}
1103
+
1104
+	/**
1105
+	 * Returns the value of the specified option.
1106
+	 *
1107
+	 * @param string $optionName The name of the option to retrieve
1108
+	 *
1109
+	 * @return mixed
1110
+	 */
1111
+	public function getOption($optionName)
1112
+	{
1113
+		return isset($this->_options[$optionName])
1114
+			? $this->_options[$optionName] : false;
1115
+	}
1116
+
1117
+	/**
1118
+	 * A simple version of http_build_query in userland. The encoded string is
1119
+	 * percentage encoded according to RFC 3986.
1120
+	 *
1121
+	 * @param array  $data      An array, which has to be converted into
1122
+	 *                          QUERY_STRING. Anything is possible.
1123
+	 * @param string $separator Separator {@link self::OPTION_SEPARATOR_OUTPUT}
1124
+	 * @param string $key       For stacked values (arrays in an array).
1125
+	 *
1126
+	 * @return string
1127
+	 */
1128
+	protected function buildQuery(array $data, $separator, $key = null)
1129
+	{
1130
+		$query = array();
1131
+		$drop_names = (
1132
+			$this->_options[self::OPTION_DROP_SEQUENCE] === true
1133
+			&& array_keys($data) === array_keys(array_values($data))
1134
+		);
1135
+		foreach ($data as $name => $value) {
1136
+			if ($this->getOption(self::OPTION_ENCODE_KEYS) === true) {
1137
+				$name = rawurlencode($name);
1138
+			}
1139
+			if ($key !== null) {
1140
+				if ($this->getOption(self::OPTION_USE_BRACKETS) === true) {
1141
+					$drop_names && $name = '';
1142
+					$name = $key . '[' . $name . ']';
1143
+				} else {
1144
+					$name = $key;
1145
+				}
1146
+			}
1147
+			if (is_array($value)) {
1148
+				$query[] = $this->buildQuery($value, $separator, $name);
1149
+			} else {
1150
+				$query[] = $name . '=' . rawurlencode($value);
1151
+			}
1152
+		}
1153
+		return implode($separator, $query);
1154
+	}
1155
+
1156
+	/**
1157
+	 * This method uses a regex to parse the url into the designated parts.
1158
+	 *
1159
+	 * @param string $url URL
1160
+	 *
1161
+	 * @return void
1162
+	 * @uses   self::$_scheme, self::setAuthority(), self::$_path, self::$_query,
1163
+	 *         self::$_fragment
1164
+	 * @see    __construct
1165
+	 */
1166
+	protected function parseUrl($url)
1167
+	{
1168
+		// The regular expression is copied verbatim from RFC 3986, appendix B.
1169
+		// The expression does not validate the URL but matches any string.
1170
+		preg_match(
1171
+			'(^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?)',
1172
+			$url, $matches
1173
+		);
1174
+
1175
+		// "path" is always present (possibly as an empty string); the rest
1176
+		// are optional.
1177
+		$this->_scheme   = !empty($matches[1]) ? $matches[2] : false;
1178
+		$this->setAuthority(!empty($matches[3]) ? $matches[4] : false);
1179
+		$this->_path     = $this->_encodeData($matches[5]);
1180
+		$this->_query    = !empty($matches[6])
1181
+						   ? $this->_encodeData($matches[7])
1182
+						   : false
1183
+			;
1184
+		$this->_fragment = !empty($matches[8]) ? $matches[9] : false;
1185
+	}
1186
+
1187
+	/**
1188
+	 * Encode characters that might have been forgotten to encode when passing
1189
+	 * in an URL. Applied onto Userinfo, Path and Query.
1190
+	 *
1191
+	 * @param string $url URL
1192
+	 *
1193
+	 * @return string
1194
+	 * @see parseUrl
1195
+	 * @see setAuthority
1196
+	 * @link https://pear.php.net/bugs/bug.php?id=20425
1197
+	 */
1198
+	private function _encodeData($url)
1199
+	{
1200
+		return preg_replace_callback(
1201
+			'([\x-\x20\x22\x3C\x3E\x7F-\xFF]+)',
1202
+			array($this, '_encodeCallback'), $url
1203
+		);
1204
+	}
1205
+
1206
+	/**
1207
+	 * callback for encoding character data
1208
+	 *
1209
+	 * @param array $matches Matches
1210
+	 *
1211
+	 * @return string
1212
+	 * @see _encodeData
1213
+	 * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
1214
+	 */
1215
+	private function _encodeCallback(array $matches)
1216
+	{
1217
+		return rawurlencode($matches[0]);
1218
+	}
1219 1219
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
      */
170 170
     public function __set($var, $arg)
171 171
     {
172
-        $method = 'set' . $var;
172
+        $method = 'set'.$var;
173 173
         if (method_exists($this, $method)) {
174 174
             $this->$method($arg);
175 175
         }
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
      */
190 190
     public function __get($var)
191 191
     {
192
-        $method = 'get' . $var;
192
+        $method = 'get'.$var;
193 193
         if (method_exists($this, $method)) {
194 194
             return $this->$method();
195 195
         }
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
     public function setUserinfo($userinfo, $password = false)
277 277
     {
278 278
         if ($password !== false) {
279
-            $userinfo .= ':' . $password;
279
+            $userinfo .= ':'.$password;
280 280
         }
281 281
 
282 282
         if ($userinfo !== false) {
@@ -352,13 +352,13 @@  discard block
 block discarded – undo
352 352
         $authority = '';
353 353
 
354 354
         if (strlen($this->_userinfo)) {
355
-            $authority .= $this->_userinfo . '@';
355
+            $authority .= $this->_userinfo.'@';
356 356
         }
357 357
 
358 358
         $authority .= $this->_host;
359 359
 
360 360
         if ($this->_port !== false) {
361
-            $authority .= ':' . $this->_port;
361
+            $authority .= ':'.$this->_port;
362 362
         }
363 363
 
364 364
         return $authority;
@@ -488,7 +488,7 @@  discard block
 block discarded – undo
488 488
         $encodeKeys  = $this->getOption(self::OPTION_ENCODE_KEYS);
489 489
         $useBrackets = $this->getOption(self::OPTION_USE_BRACKETS);
490 490
 
491
-        $return  = array();
491
+        $return = array();
492 492
 
493 493
         for ($part = strtok($this->_query, $separator);
494 494
             strlen($part);
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
                 $return = $this->_queryArrayByKey($key, $value, $return);
506 506
             } else {
507 507
                 if (isset($return[$key])) {
508
-                    $return[$key]  = (array) $return[$key];
508
+                    $return[$key] = (array) $return[$key];
509 509
                     $return[$key][] = $value;
510 510
                 } else {
511 511
                     $return[$key] = $value;
@@ -585,7 +585,7 @@  discard block
 block discarded – undo
585 585
                 }
586 586
                 // @codeCoverageIgnoreStart
587 587
                 throw new Exception(
588
-                    'Net_URL2 Internal Error: '. __METHOD__ .'(): ' .
588
+                    'Net_URL2 Internal Error: '.__METHOD__.'(): '.
589 589
                     'Opening bracket [ must exist at offset 0'
590 590
                 );
591 591
                 // @codeCoverageIgnoreEnd
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
                 // See as well the first exception for the opening bracket.
599 599
                 // @codeCoverageIgnoreStart
600 600
                 throw new Exception(
601
-                    'Net_URL2 Internal Error: '. __METHOD__ .'(): ' .
601
+                    'Net_URL2 Internal Error: '.__METHOD__.'(): '.
602 602
                     'Closing bracket ] must exist, not found'
603 603
                 );
604 604
                 // @codeCoverageIgnoreEnd
@@ -702,7 +702,7 @@  discard block
 block discarded – undo
702 702
         $url = '';
703 703
 
704 704
         if ($this->_scheme !== false) {
705
-            $url .= $this->_scheme . ':';
705
+            $url .= $this->_scheme.':';
706 706
         }
707 707
 
708 708
         $authority = $this->getAuthority();
@@ -713,11 +713,11 @@  discard block
 block discarded – undo
713 713
         $url .= $this->_buildAuthorityAndPath($authority, $this->_path);
714 714
 
715 715
         if ($this->_query !== false) {
716
-            $url .= '?' . $this->_query;
716
+            $url .= '?'.$this->_query;
717 717
         }
718 718
 
719 719
         if ($this->_fragment !== false) {
720
-            $url .= '#' . $this->_fragment;
720
+            $url .= '#'.$this->_fragment;
721 721
         }
722 722
 
723 723
         return $url;
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
 
741 741
         $terminator = ($path !== '' && $path[0] !== '/') ? '/' : '';
742 742
 
743
-        return '//' . $authority . $terminator . $path;
743
+        return '//'.$authority.$terminator.$path;
744 744
     }
745 745
 
746 746
     /**
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
             && strlen($this->_path)
824 824
             && $this->_path[0] !== '/'
825 825
         ) {
826
-            $this->_path = '/' . $this->_path;
826
+            $this->_path = '/'.$this->_path;
827 827
         }
828 828
     }
829 829
 
@@ -924,7 +924,7 @@  discard block
 block discarded – undo
924 924
                     } else {
925 925
                         // Merge paths (RFC 3986, section 5.2.3)
926 926
                         if ($this->_host !== false && $this->_path == '') {
927
-                            $target->_path = '/' . $reference->_path;
927
+                            $target->_path = '/'.$reference->_path;
928 928
                         } else {
929 929
                             $i = strrpos($this->_path, '/');
930 930
                             if ($i !== false) {
@@ -991,10 +991,10 @@  discard block
 block discarded – undo
991 991
                 $path = substr($path, 3);
992 992
             } elseif (substr($path, 0, 3) === '/./' || $path === '/.') {
993 993
                 // Step 2.B
994
-                $path = '/' . substr($path, 3);
994
+                $path = '/'.substr($path, 3);
995 995
             } elseif (substr($path, 0, 4) === '/../' || $path === '/..') {
996 996
                 // Step 2.C
997
-                $path   = '/' . substr($path, 4);
997
+                $path   = '/'.substr($path, 4);
998 998
                 $i      = strrpos($output, '/');
999 999
                 $output = $i === false ? '' : substr($output, 0, $i);
1000 1000
             } elseif ($path === '.' || $path === '..') {
@@ -1139,7 +1139,7 @@  discard block
 block discarded – undo
1139 1139
             if ($key !== null) {
1140 1140
                 if ($this->getOption(self::OPTION_USE_BRACKETS) === true) {
1141 1141
                     $drop_names && $name = '';
1142
-                    $name = $key . '[' . $name . ']';
1142
+                    $name = $key.'['.$name.']';
1143 1143
                 } else {
1144 1144
                     $name = $key;
1145 1145
                 }
@@ -1147,7 +1147,7 @@  discard block
 block discarded – undo
1147 1147
             if (is_array($value)) {
1148 1148
                 $query[] = $this->buildQuery($value, $separator, $name);
1149 1149
             } else {
1150
-                $query[] = $name . '=' . rawurlencode($value);
1150
+                $query[] = $name.'='.rawurlencode($value);
1151 1151
             }
1152 1152
         }
1153 1153
         return implode($separator, $query);
Please login to merge, or discard this patch.
libs/PEAR.1.9.5/PEAR/Exception.php 4 patches
Doc Comments   +2 added lines patch added patch discarded remove patch
@@ -117,6 +117,8 @@
 block discarded – undo
117 117
      * @param string exception message
118 118
      * @param int|Exception|PEAR_Error|array|null exception cause
119 119
      * @param int|null exception code or null
120
+     * @param string|null $message
121
+     * @param integer $p2
120 122
      */
121 123
     public function __construct($message, $p2 = null, $p3 = null)
122 124
     {
Please login to merge, or discard this patch.
Indentation   +275 added lines, -275 removed lines patch added patch discarded remove patch
@@ -96,294 +96,294 @@
 block discarded – undo
96 96
  */
97 97
 class PEAR_Exception extends Exception
98 98
 {
99
-    const OBSERVER_PRINT = -2;
100
-    const OBSERVER_TRIGGER = -4;
101
-    const OBSERVER_DIE = -8;
102
-    protected $cause;
103
-    private static $_observers = array();
104
-    private static $_uniqueid = 0;
105
-    private $_trace;
99
+	const OBSERVER_PRINT = -2;
100
+	const OBSERVER_TRIGGER = -4;
101
+	const OBSERVER_DIE = -8;
102
+	protected $cause;
103
+	private static $_observers = array();
104
+	private static $_uniqueid = 0;
105
+	private $_trace;
106 106
 
107
-    /**
108
-     * Supported signatures:
109
-     *  - PEAR_Exception(string $message);
110
-     *  - PEAR_Exception(string $message, int $code);
111
-     *  - PEAR_Exception(string $message, Exception $cause);
112
-     *  - PEAR_Exception(string $message, Exception $cause, int $code);
113
-     *  - PEAR_Exception(string $message, PEAR_Error $cause);
114
-     *  - PEAR_Exception(string $message, PEAR_Error $cause, int $code);
115
-     *  - PEAR_Exception(string $message, array $causes);
116
-     *  - PEAR_Exception(string $message, array $causes, int $code);
117
-     * @param string exception message
118
-     * @param int|Exception|PEAR_Error|array|null exception cause
119
-     * @param int|null exception code or null
120
-     */
121
-    public function __construct($message, $p2 = null, $p3 = null)
122
-    {
123
-        if (is_int($p2)) {
124
-            $code = $p2;
125
-            $this->cause = null;
126
-        } elseif (is_object($p2) || is_array($p2)) {
127
-            // using is_object allows both Exception and PEAR_Error
128
-            if (is_object($p2) && !($p2 instanceof Exception)) {
129
-                if (!class_exists('PEAR_Error') || !($p2 instanceof PEAR_Error)) {
130
-                    throw new PEAR_Exception('exception cause must be Exception, ' .
131
-                        'array, or PEAR_Error');
132
-                }
133
-            }
134
-            $code = $p3;
135
-            if (is_array($p2) && isset($p2['message'])) {
136
-                // fix potential problem of passing in a single warning
137
-                $p2 = array($p2);
138
-            }
139
-            $this->cause = $p2;
140
-        } else {
141
-            $code = null;
142
-            $this->cause = null;
143
-        }
144
-        parent::__construct($message, $code);
145
-        $this->signal();
146
-    }
107
+	/**
108
+	 * Supported signatures:
109
+	 *  - PEAR_Exception(string $message);
110
+	 *  - PEAR_Exception(string $message, int $code);
111
+	 *  - PEAR_Exception(string $message, Exception $cause);
112
+	 *  - PEAR_Exception(string $message, Exception $cause, int $code);
113
+	 *  - PEAR_Exception(string $message, PEAR_Error $cause);
114
+	 *  - PEAR_Exception(string $message, PEAR_Error $cause, int $code);
115
+	 *  - PEAR_Exception(string $message, array $causes);
116
+	 *  - PEAR_Exception(string $message, array $causes, int $code);
117
+	 * @param string exception message
118
+	 * @param int|Exception|PEAR_Error|array|null exception cause
119
+	 * @param int|null exception code or null
120
+	 */
121
+	public function __construct($message, $p2 = null, $p3 = null)
122
+	{
123
+		if (is_int($p2)) {
124
+			$code = $p2;
125
+			$this->cause = null;
126
+		} elseif (is_object($p2) || is_array($p2)) {
127
+			// using is_object allows both Exception and PEAR_Error
128
+			if (is_object($p2) && !($p2 instanceof Exception)) {
129
+				if (!class_exists('PEAR_Error') || !($p2 instanceof PEAR_Error)) {
130
+					throw new PEAR_Exception('exception cause must be Exception, ' .
131
+						'array, or PEAR_Error');
132
+				}
133
+			}
134
+			$code = $p3;
135
+			if (is_array($p2) && isset($p2['message'])) {
136
+				// fix potential problem of passing in a single warning
137
+				$p2 = array($p2);
138
+			}
139
+			$this->cause = $p2;
140
+		} else {
141
+			$code = null;
142
+			$this->cause = null;
143
+		}
144
+		parent::__construct($message, $code);
145
+		$this->signal();
146
+	}
147 147
 
148
-    /**
149
-     * @param mixed $callback  - A valid php callback, see php func is_callable()
150
-     *                         - A PEAR_Exception::OBSERVER_* constant
151
-     *                         - An array(const PEAR_Exception::OBSERVER_*,
152
-     *                           mixed $options)
153
-     * @param string $label    The name of the observer. Use this if you want
154
-     *                         to remove it later with removeObserver()
155
-     */
156
-    public static function addObserver($callback, $label = 'default')
157
-    {
158
-        self::$_observers[$label] = $callback;
159
-    }
148
+	/**
149
+	 * @param mixed $callback  - A valid php callback, see php func is_callable()
150
+	 *                         - A PEAR_Exception::OBSERVER_* constant
151
+	 *                         - An array(const PEAR_Exception::OBSERVER_*,
152
+	 *                           mixed $options)
153
+	 * @param string $label    The name of the observer. Use this if you want
154
+	 *                         to remove it later with removeObserver()
155
+	 */
156
+	public static function addObserver($callback, $label = 'default')
157
+	{
158
+		self::$_observers[$label] = $callback;
159
+	}
160 160
 
161
-    public static function removeObserver($label = 'default')
162
-    {
163
-        unset(self::$_observers[$label]);
164
-    }
161
+	public static function removeObserver($label = 'default')
162
+	{
163
+		unset(self::$_observers[$label]);
164
+	}
165 165
 
166
-    /**
167
-     * @return int unique identifier for an observer
168
-     */
169
-    public static function getUniqueId()
170
-    {
171
-        return self::$_uniqueid++;
172
-    }
166
+	/**
167
+	 * @return int unique identifier for an observer
168
+	 */
169
+	public static function getUniqueId()
170
+	{
171
+		return self::$_uniqueid++;
172
+	}
173 173
 
174
-    private function signal()
175
-    {
176
-        foreach (self::$_observers as $func) {
177
-            if (is_callable($func)) {
178
-                call_user_func($func, $this);
179
-                continue;
180
-            }
181
-            settype($func, 'array');
182
-            switch ($func[0]) {
183
-                case self::OBSERVER_PRINT :
184
-                    $f = (isset($func[1])) ? $func[1] : '%s';
185
-                    printf($f, $this->getMessage());
186
-                    break;
187
-                case self::OBSERVER_TRIGGER :
188
-                    $f = (isset($func[1])) ? $func[1] : E_USER_NOTICE;
189
-                    trigger_error($this->getMessage(), $f);
190
-                    break;
191
-                case self::OBSERVER_DIE :
192
-                    $f = (isset($func[1])) ? $func[1] : '%s';
193
-                    die(printf($f, $this->getMessage()));
194
-                    break;
195
-                default:
196
-                    trigger_error('invalid observer type', E_USER_WARNING);
197
-            }
198
-        }
199
-    }
174
+	private function signal()
175
+	{
176
+		foreach (self::$_observers as $func) {
177
+			if (is_callable($func)) {
178
+				call_user_func($func, $this);
179
+				continue;
180
+			}
181
+			settype($func, 'array');
182
+			switch ($func[0]) {
183
+				case self::OBSERVER_PRINT :
184
+					$f = (isset($func[1])) ? $func[1] : '%s';
185
+					printf($f, $this->getMessage());
186
+					break;
187
+				case self::OBSERVER_TRIGGER :
188
+					$f = (isset($func[1])) ? $func[1] : E_USER_NOTICE;
189
+					trigger_error($this->getMessage(), $f);
190
+					break;
191
+				case self::OBSERVER_DIE :
192
+					$f = (isset($func[1])) ? $func[1] : '%s';
193
+					die(printf($f, $this->getMessage()));
194
+					break;
195
+				default:
196
+					trigger_error('invalid observer type', E_USER_WARNING);
197
+			}
198
+		}
199
+	}
200 200
 
201
-    /**
202
-     * Return specific error information that can be used for more detailed
203
-     * error messages or translation.
204
-     *
205
-     * This method may be overridden in child exception classes in order
206
-     * to add functionality not present in PEAR_Exception and is a placeholder
207
-     * to define API
208
-     *
209
-     * The returned array must be an associative array of parameter => value like so:
210
-     * <pre>
211
-     * array('name' => $name, 'context' => array(...))
212
-     * </pre>
213
-     * @return array
214
-     */
215
-    public function getErrorData()
216
-    {
217
-        return array();
218
-    }
201
+	/**
202
+	 * Return specific error information that can be used for more detailed
203
+	 * error messages or translation.
204
+	 *
205
+	 * This method may be overridden in child exception classes in order
206
+	 * to add functionality not present in PEAR_Exception and is a placeholder
207
+	 * to define API
208
+	 *
209
+	 * The returned array must be an associative array of parameter => value like so:
210
+	 * <pre>
211
+	 * array('name' => $name, 'context' => array(...))
212
+	 * </pre>
213
+	 * @return array
214
+	 */
215
+	public function getErrorData()
216
+	{
217
+		return array();
218
+	}
219 219
 
220
-    /**
221
-     * Returns the exception that caused this exception to be thrown
222
-     * @access public
223
-     * @return Exception|array The context of the exception
224
-     */
225
-    public function getCause()
226
-    {
227
-        return $this->cause;
228
-    }
220
+	/**
221
+	 * Returns the exception that caused this exception to be thrown
222
+	 * @access public
223
+	 * @return Exception|array The context of the exception
224
+	 */
225
+	public function getCause()
226
+	{
227
+		return $this->cause;
228
+	}
229 229
 
230
-    /**
231
-     * Function must be public to call on caused exceptions
232
-     * @param array
233
-     */
234
-    public function getCauseMessage(&$causes)
235
-    {
236
-        $trace = $this->getTraceSafe();
237
-        $cause = array('class'   => get_class($this),
238
-                       'message' => $this->message,
239
-                       'file' => 'unknown',
240
-                       'line' => 'unknown');
241
-        if (isset($trace[0])) {
242
-            if (isset($trace[0]['file'])) {
243
-                $cause['file'] = $trace[0]['file'];
244
-                $cause['line'] = $trace[0]['line'];
245
-            }
246
-        }
247
-        $causes[] = $cause;
248
-        if ($this->cause instanceof PEAR_Exception) {
249
-            $this->cause->getCauseMessage($causes);
250
-        } elseif ($this->cause instanceof Exception) {
251
-            $causes[] = array('class'   => get_class($this->cause),
252
-                              'message' => $this->cause->getMessage(),
253
-                              'file' => $this->cause->getFile(),
254
-                              'line' => $this->cause->getLine());
255
-        } elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) {
256
-            $causes[] = array('class' => get_class($this->cause),
257
-                              'message' => $this->cause->getMessage(),
258
-                              'file' => 'unknown',
259
-                              'line' => 'unknown');
260
-        } elseif (is_array($this->cause)) {
261
-            foreach ($this->cause as $cause) {
262
-                if ($cause instanceof PEAR_Exception) {
263
-                    $cause->getCauseMessage($causes);
264
-                } elseif ($cause instanceof Exception) {
265
-                    $causes[] = array('class'   => get_class($cause),
266
-                                   'message' => $cause->getMessage(),
267
-                                   'file' => $cause->getFile(),
268
-                                   'line' => $cause->getLine());
269
-                } elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) {
270
-                    $causes[] = array('class' => get_class($cause),
271
-                                      'message' => $cause->getMessage(),
272
-                                      'file' => 'unknown',
273
-                                      'line' => 'unknown');
274
-                } elseif (is_array($cause) && isset($cause['message'])) {
275
-                    // PEAR_ErrorStack warning
276
-                    $causes[] = array(
277
-                        'class' => $cause['package'],
278
-                        'message' => $cause['message'],
279
-                        'file' => isset($cause['context']['file']) ?
280
-                                            $cause['context']['file'] :
281
-                                            'unknown',
282
-                        'line' => isset($cause['context']['line']) ?
283
-                                            $cause['context']['line'] :
284
-                                            'unknown',
285
-                    );
286
-                }
287
-            }
288
-        }
289
-    }
230
+	/**
231
+	 * Function must be public to call on caused exceptions
232
+	 * @param array
233
+	 */
234
+	public function getCauseMessage(&$causes)
235
+	{
236
+		$trace = $this->getTraceSafe();
237
+		$cause = array('class'   => get_class($this),
238
+					   'message' => $this->message,
239
+					   'file' => 'unknown',
240
+					   'line' => 'unknown');
241
+		if (isset($trace[0])) {
242
+			if (isset($trace[0]['file'])) {
243
+				$cause['file'] = $trace[0]['file'];
244
+				$cause['line'] = $trace[0]['line'];
245
+			}
246
+		}
247
+		$causes[] = $cause;
248
+		if ($this->cause instanceof PEAR_Exception) {
249
+			$this->cause->getCauseMessage($causes);
250
+		} elseif ($this->cause instanceof Exception) {
251
+			$causes[] = array('class'   => get_class($this->cause),
252
+							  'message' => $this->cause->getMessage(),
253
+							  'file' => $this->cause->getFile(),
254
+							  'line' => $this->cause->getLine());
255
+		} elseif (class_exists('PEAR_Error') && $this->cause instanceof PEAR_Error) {
256
+			$causes[] = array('class' => get_class($this->cause),
257
+							  'message' => $this->cause->getMessage(),
258
+							  'file' => 'unknown',
259
+							  'line' => 'unknown');
260
+		} elseif (is_array($this->cause)) {
261
+			foreach ($this->cause as $cause) {
262
+				if ($cause instanceof PEAR_Exception) {
263
+					$cause->getCauseMessage($causes);
264
+				} elseif ($cause instanceof Exception) {
265
+					$causes[] = array('class'   => get_class($cause),
266
+								   'message' => $cause->getMessage(),
267
+								   'file' => $cause->getFile(),
268
+								   'line' => $cause->getLine());
269
+				} elseif (class_exists('PEAR_Error') && $cause instanceof PEAR_Error) {
270
+					$causes[] = array('class' => get_class($cause),
271
+									  'message' => $cause->getMessage(),
272
+									  'file' => 'unknown',
273
+									  'line' => 'unknown');
274
+				} elseif (is_array($cause) && isset($cause['message'])) {
275
+					// PEAR_ErrorStack warning
276
+					$causes[] = array(
277
+						'class' => $cause['package'],
278
+						'message' => $cause['message'],
279
+						'file' => isset($cause['context']['file']) ?
280
+											$cause['context']['file'] :
281
+											'unknown',
282
+						'line' => isset($cause['context']['line']) ?
283
+											$cause['context']['line'] :
284
+											'unknown',
285
+					);
286
+				}
287
+			}
288
+		}
289
+	}
290 290
 
291
-    public function getTraceSafe()
292
-    {
293
-        if (!isset($this->_trace)) {
294
-            $this->_trace = $this->getTrace();
295
-            if (empty($this->_trace)) {
296
-                $backtrace = debug_backtrace();
297
-                $this->_trace = array($backtrace[count($backtrace)-1]);
298
-            }
299
-        }
300
-        return $this->_trace;
301
-    }
291
+	public function getTraceSafe()
292
+	{
293
+		if (!isset($this->_trace)) {
294
+			$this->_trace = $this->getTrace();
295
+			if (empty($this->_trace)) {
296
+				$backtrace = debug_backtrace();
297
+				$this->_trace = array($backtrace[count($backtrace)-1]);
298
+			}
299
+		}
300
+		return $this->_trace;
301
+	}
302 302
 
303
-    public function getErrorClass()
304
-    {
305
-        $trace = $this->getTraceSafe();
306
-        return $trace[0]['class'];
307
-    }
303
+	public function getErrorClass()
304
+	{
305
+		$trace = $this->getTraceSafe();
306
+		return $trace[0]['class'];
307
+	}
308 308
 
309
-    public function getErrorMethod()
310
-    {
311
-        $trace = $this->getTraceSafe();
312
-        return $trace[0]['function'];
313
-    }
309
+	public function getErrorMethod()
310
+	{
311
+		$trace = $this->getTraceSafe();
312
+		return $trace[0]['function'];
313
+	}
314 314
 
315
-    public function __toString()
316
-    {
317
-        if (isset($_SERVER['REQUEST_URI'])) {
318
-            return $this->toHtml();
319
-        }
320
-        return $this->toText();
321
-    }
315
+	public function __toString()
316
+	{
317
+		if (isset($_SERVER['REQUEST_URI'])) {
318
+			return $this->toHtml();
319
+		}
320
+		return $this->toText();
321
+	}
322 322
 
323
-    public function toHtml()
324
-    {
325
-        $trace = $this->getTraceSafe();
326
-        $causes = array();
327
-        $this->getCauseMessage($causes);
328
-        $html =  '<table style="border: 1px" cellspacing="0">' . "\n";
329
-        foreach ($causes as $i => $cause) {
330
-            $html .= '<tr><td colspan="3" style="background: #ff9999">'
331
-               . str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
332
-               . htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
333
-               . 'on line <b>' . $cause['line'] . '</b>'
334
-               . "</td></tr>\n";
335
-        }
336
-        $html .= '<tr><td colspan="3" style="background-color: #aaaaaa; text-align: center; font-weight: bold;">Exception trace</td></tr>' . "\n"
337
-               . '<tr><td style="text-align: center; background: #cccccc; width:20px; font-weight: bold;">#</td>'
338
-               . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Function</td>'
339
-               . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>' . "\n";
323
+	public function toHtml()
324
+	{
325
+		$trace = $this->getTraceSafe();
326
+		$causes = array();
327
+		$this->getCauseMessage($causes);
328
+		$html =  '<table style="border: 1px" cellspacing="0">' . "\n";
329
+		foreach ($causes as $i => $cause) {
330
+			$html .= '<tr><td colspan="3" style="background: #ff9999">'
331
+			   . str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
332
+			   . htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
333
+			   . 'on line <b>' . $cause['line'] . '</b>'
334
+			   . "</td></tr>\n";
335
+		}
336
+		$html .= '<tr><td colspan="3" style="background-color: #aaaaaa; text-align: center; font-weight: bold;">Exception trace</td></tr>' . "\n"
337
+			   . '<tr><td style="text-align: center; background: #cccccc; width:20px; font-weight: bold;">#</td>'
338
+			   . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Function</td>'
339
+			   . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>' . "\n";
340 340
 
341
-        foreach ($trace as $k => $v) {
342
-            $html .= '<tr><td style="text-align: center;">' . $k . '</td>'
343
-                   . '<td>';
344
-            if (!empty($v['class'])) {
345
-                $html .= $v['class'] . $v['type'];
346
-            }
347
-            $html .= $v['function'];
348
-            $args = array();
349
-            if (!empty($v['args'])) {
350
-                foreach ($v['args'] as $arg) {
351
-                    if (is_null($arg)) $args[] = 'null';
352
-                    elseif (is_array($arg)) $args[] = 'Array';
353
-                    elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')';
354
-                    elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false';
355
-                    elseif (is_int($arg) || is_double($arg)) $args[] = $arg;
356
-                    else {
357
-                        $arg = (string)$arg;
358
-                        $str = htmlspecialchars(substr($arg, 0, 16));
359
-                        if (strlen($arg) > 16) $str .= '&hellip;';
360
-                        $args[] = "'" . $str . "'";
361
-                    }
362
-                }
363
-            }
364
-            $html .= '(' . implode(', ',$args) . ')'
365
-                   . '</td>'
366
-                   . '<td>' . (isset($v['file']) ? $v['file'] : 'unknown')
367
-                   . ':' . (isset($v['line']) ? $v['line'] : 'unknown')
368
-                   . '</td></tr>' . "\n";
369
-        }
370
-        $html .= '<tr><td style="text-align: center;">' . ($k+1) . '</td>'
371
-               . '<td>{main}</td>'
372
-               . '<td>&nbsp;</td></tr>' . "\n"
373
-               . '</table>';
374
-        return $html;
375
-    }
341
+		foreach ($trace as $k => $v) {
342
+			$html .= '<tr><td style="text-align: center;">' . $k . '</td>'
343
+				   . '<td>';
344
+			if (!empty($v['class'])) {
345
+				$html .= $v['class'] . $v['type'];
346
+			}
347
+			$html .= $v['function'];
348
+			$args = array();
349
+			if (!empty($v['args'])) {
350
+				foreach ($v['args'] as $arg) {
351
+					if (is_null($arg)) $args[] = 'null';
352
+					elseif (is_array($arg)) $args[] = 'Array';
353
+					elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')';
354
+					elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false';
355
+					elseif (is_int($arg) || is_double($arg)) $args[] = $arg;
356
+					else {
357
+						$arg = (string)$arg;
358
+						$str = htmlspecialchars(substr($arg, 0, 16));
359
+						if (strlen($arg) > 16) $str .= '&hellip;';
360
+						$args[] = "'" . $str . "'";
361
+					}
362
+				}
363
+			}
364
+			$html .= '(' . implode(', ',$args) . ')'
365
+				   . '</td>'
366
+				   . '<td>' . (isset($v['file']) ? $v['file'] : 'unknown')
367
+				   . ':' . (isset($v['line']) ? $v['line'] : 'unknown')
368
+				   . '</td></tr>' . "\n";
369
+		}
370
+		$html .= '<tr><td style="text-align: center;">' . ($k+1) . '</td>'
371
+			   . '<td>{main}</td>'
372
+			   . '<td>&nbsp;</td></tr>' . "\n"
373
+			   . '</table>';
374
+		return $html;
375
+	}
376 376
 
377
-    public function toText()
378
-    {
379
-        $causes = array();
380
-        $this->getCauseMessage($causes);
381
-        $causeMsg = '';
382
-        foreach ($causes as $i => $cause) {
383
-            $causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': '
384
-                   . $cause['message'] . ' in ' . $cause['file']
385
-                   . ' on line ' . $cause['line'] . "\n";
386
-        }
387
-        return $causeMsg . $this->getTraceAsString();
388
-    }
377
+	public function toText()
378
+	{
379
+		$causes = array();
380
+		$this->getCauseMessage($causes);
381
+		$causeMsg = '';
382
+		foreach ($causes as $i => $cause) {
383
+			$causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': '
384
+				   . $cause['message'] . ' in ' . $cause['file']
385
+				   . ' on line ' . $cause['line'] . "\n";
386
+		}
387
+		return $causeMsg . $this->getTraceAsString();
388
+	}
389 389
 }
390 390
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +14 added lines, -7 removed lines patch added patch discarded remove patch
@@ -348,15 +348,22 @@
 block discarded – undo
348 348
             $args = array();
349 349
             if (!empty($v['args'])) {
350 350
                 foreach ($v['args'] as $arg) {
351
-                    if (is_null($arg)) $args[] = 'null';
352
-                    elseif (is_array($arg)) $args[] = 'Array';
353
-                    elseif (is_object($arg)) $args[] = 'Object('.get_class($arg).')';
354
-                    elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false';
355
-                    elseif (is_int($arg) || is_double($arg)) $args[] = $arg;
356
-                    else {
351
+                    if (is_null($arg)) {
352
+                    	$args[] = 'null';
353
+                    } elseif (is_array($arg)) {
354
+                    	$args[] = 'Array';
355
+                    } elseif (is_object($arg)) {
356
+                    	$args[] = 'Object('.get_class($arg).')';
357
+                    } elseif (is_bool($arg)) {
358
+                    	$args[] = $arg ? 'true' : 'false';
359
+                    } elseif (is_int($arg) || is_double($arg)) {
360
+                    	$args[] = $arg;
361
+                    } else {
357 362
                         $arg = (string)$arg;
358 363
                         $str = htmlspecialchars(substr($arg, 0, 16));
359
-                        if (strlen($arg) > 16) $str .= '&hellip;';
364
+                        if (strlen($arg) > 16) {
365
+                        	$str .= '&hellip;';
366
+                        }
360 367
                         $args[] = "'" . $str . "'";
361 368
                     }
362 369
                 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -26 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
             // using is_object allows both Exception and PEAR_Error
128 128
             if (is_object($p2) && !($p2 instanceof Exception)) {
129 129
                 if (!class_exists('PEAR_Error') || !($p2 instanceof PEAR_Error)) {
130
-                    throw new PEAR_Exception('exception cause must be Exception, ' .
130
+                    throw new PEAR_Exception('exception cause must be Exception, '.
131 131
                         'array, or PEAR_Error');
132 132
                 }
133 133
             }
@@ -277,11 +277,9 @@  discard block
 block discarded – undo
277 277
                         'class' => $cause['package'],
278 278
                         'message' => $cause['message'],
279 279
                         'file' => isset($cause['context']['file']) ?
280
-                                            $cause['context']['file'] :
281
-                                            'unknown',
280
+                                            $cause['context']['file'] : 'unknown',
282 281
                         'line' => isset($cause['context']['line']) ?
283
-                                            $cause['context']['line'] :
284
-                                            'unknown',
282
+                                            $cause['context']['line'] : 'unknown',
285 283
                     );
286 284
                 }
287 285
             }
@@ -294,7 +292,7 @@  discard block
 block discarded – undo
294 292
             $this->_trace = $this->getTrace();
295 293
             if (empty($this->_trace)) {
296 294
                 $backtrace = debug_backtrace();
297
-                $this->_trace = array($backtrace[count($backtrace)-1]);
295
+                $this->_trace = array($backtrace[count($backtrace) - 1]);
298 296
             }
299 297
         }
300 298
         return $this->_trace;
@@ -325,24 +323,24 @@  discard block
 block discarded – undo
325 323
         $trace = $this->getTraceSafe();
326 324
         $causes = array();
327 325
         $this->getCauseMessage($causes);
328
-        $html =  '<table style="border: 1px" cellspacing="0">' . "\n";
326
+        $html = '<table style="border: 1px" cellspacing="0">'."\n";
329 327
         foreach ($causes as $i => $cause) {
330 328
             $html .= '<tr><td colspan="3" style="background: #ff9999">'
331
-               . str_repeat('-', $i) . ' <b>' . $cause['class'] . '</b>: '
332
-               . htmlspecialchars($cause['message']) . ' in <b>' . $cause['file'] . '</b> '
333
-               . 'on line <b>' . $cause['line'] . '</b>'
329
+               . str_repeat('-', $i).' <b>'.$cause['class'].'</b>: '
330
+               . htmlspecialchars($cause['message']).' in <b>'.$cause['file'].'</b> '
331
+               . 'on line <b>'.$cause['line'].'</b>'
334 332
                . "</td></tr>\n";
335 333
         }
336
-        $html .= '<tr><td colspan="3" style="background-color: #aaaaaa; text-align: center; font-weight: bold;">Exception trace</td></tr>' . "\n"
334
+        $html .= '<tr><td colspan="3" style="background-color: #aaaaaa; text-align: center; font-weight: bold;">Exception trace</td></tr>'."\n"
337 335
                . '<tr><td style="text-align: center; background: #cccccc; width:20px; font-weight: bold;">#</td>'
338 336
                . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Function</td>'
339
-               . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>' . "\n";
337
+               . '<td style="text-align: center; background: #cccccc; font-weight: bold;">Location</td></tr>'."\n";
340 338
 
341 339
         foreach ($trace as $k => $v) {
342
-            $html .= '<tr><td style="text-align: center;">' . $k . '</td>'
340
+            $html .= '<tr><td style="text-align: center;">'.$k.'</td>'
343 341
                    . '<td>';
344 342
             if (!empty($v['class'])) {
345
-                $html .= $v['class'] . $v['type'];
343
+                $html .= $v['class'].$v['type'];
346 344
             }
347 345
             $html .= $v['function'];
348 346
             $args = array();
@@ -354,22 +352,22 @@  discard block
 block discarded – undo
354 352
                     elseif (is_bool($arg)) $args[] = $arg ? 'true' : 'false';
355 353
                     elseif (is_int($arg) || is_double($arg)) $args[] = $arg;
356 354
                     else {
357
-                        $arg = (string)$arg;
355
+                        $arg = (string) $arg;
358 356
                         $str = htmlspecialchars(substr($arg, 0, 16));
359 357
                         if (strlen($arg) > 16) $str .= '&hellip;';
360
-                        $args[] = "'" . $str . "'";
358
+                        $args[] = "'".$str."'";
361 359
                     }
362 360
                 }
363 361
             }
364
-            $html .= '(' . implode(', ',$args) . ')'
362
+            $html .= '('.implode(', ', $args).')'
365 363
                    . '</td>'
366
-                   . '<td>' . (isset($v['file']) ? $v['file'] : 'unknown')
367
-                   . ':' . (isset($v['line']) ? $v['line'] : 'unknown')
368
-                   . '</td></tr>' . "\n";
364
+                   . '<td>'.(isset($v['file']) ? $v['file'] : 'unknown')
365
+                   . ':'.(isset($v['line']) ? $v['line'] : 'unknown')
366
+                   . '</td></tr>'."\n";
369 367
         }
370
-        $html .= '<tr><td style="text-align: center;">' . ($k+1) . '</td>'
368
+        $html .= '<tr><td style="text-align: center;">'.($k + 1).'</td>'
371 369
                . '<td>{main}</td>'
372
-               . '<td>&nbsp;</td></tr>' . "\n"
370
+               . '<td>&nbsp;</td></tr>'."\n"
373 371
                . '</table>';
374 372
         return $html;
375 373
     }
@@ -380,10 +378,10 @@  discard block
 block discarded – undo
380 378
         $this->getCauseMessage($causes);
381 379
         $causeMsg = '';
382 380
         foreach ($causes as $i => $cause) {
383
-            $causeMsg .= str_repeat(' ', $i) . $cause['class'] . ': '
384
-                   . $cause['message'] . ' in ' . $cause['file']
385
-                   . ' on line ' . $cause['line'] . "\n";
381
+            $causeMsg .= str_repeat(' ', $i).$cause['class'].': '
382
+                   . $cause['message'].' in '.$cause['file']
383
+                   . ' on line '.$cause['line']."\n";
386 384
         }
387
-        return $causeMsg . $this->getTraceAsString();
385
+        return $causeMsg.$this->getTraceAsString();
388 386
     }
389 387
 }
390 388
\ No newline at end of file
Please login to merge, or discard this patch.
libs/PEAR.1.9/HTTP/Request2.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -269,7 +269,7 @@
 block discarded – undo
269 269
    /**
270 270
     * Returns the request URL
271 271
     *
272
-    * @return   Net_URL2
272
+    * @return   string
273 273
     */
274 274
     public function getUrl()
275 275
     {
Please login to merge, or discard this patch.
Indentation   +405 added lines, -405 removed lines patch added patch discarded remove patch
@@ -67,14 +67,14 @@  discard block
 block discarded – undo
67 67
     *
68 68
     * @link http://tools.ietf.org/html/rfc2616#section-5.1.1
69 69
     */
70
-    const METHOD_OPTIONS = 'OPTIONS';
71
-    const METHOD_GET     = 'GET';
72
-    const METHOD_HEAD    = 'HEAD';
73
-    const METHOD_POST    = 'POST';
74
-    const METHOD_PUT     = 'PUT';
75
-    const METHOD_DELETE  = 'DELETE';
76
-    const METHOD_TRACE   = 'TRACE';
77
-    const METHOD_CONNECT = 'CONNECT';
70
+	const METHOD_OPTIONS = 'OPTIONS';
71
+	const METHOD_GET     = 'GET';
72
+	const METHOD_HEAD    = 'HEAD';
73
+	const METHOD_POST    = 'POST';
74
+	const METHOD_PUT     = 'PUT';
75
+	const METHOD_DELETE  = 'DELETE';
76
+	const METHOD_TRACE   = 'TRACE';
77
+	const METHOD_CONNECT = 'CONNECT';
78 78
    /**#@-*/
79 79
 
80 80
    /**#@+
@@ -82,129 +82,129 @@  discard block
 block discarded – undo
82 82
     *
83 83
     * @link http://tools.ietf.org/html/rfc2617
84 84
     */
85
-    const AUTH_BASIC  = 'basic';
86
-    const AUTH_DIGEST = 'digest';
85
+	const AUTH_BASIC  = 'basic';
86
+	const AUTH_DIGEST = 'digest';
87 87
    /**#@-*/
88 88
 
89 89
    /**
90 90
     * Regular expression used to check for invalid symbols in RFC 2616 tokens
91 91
     * @link http://pear.php.net/bugs/bug.php?id=15630
92 92
     */
93
-    const REGEXP_INVALID_TOKEN = '![\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]!';
93
+	const REGEXP_INVALID_TOKEN = '![\x00-\x1f\x7f-\xff()<>@,;:\\\\"/\[\]?={}\s]!';
94 94
 
95 95
    /**
96 96
     * Regular expression used to check for invalid symbols in cookie strings
97 97
     * @link http://pear.php.net/bugs/bug.php?id=15630
98 98
     * @link http://web.archive.org/web/20080331104521/http://cgi.netscape.com/newsref/std/cookie_spec.html
99 99
     */
100
-    const REGEXP_INVALID_COOKIE = '/[\s,;]/';
100
+	const REGEXP_INVALID_COOKIE = '/[\s,;]/';
101 101
 
102 102
    /**
103 103
     * Fileinfo magic database resource
104 104
     * @var  resource
105 105
     * @see  detectMimeType()
106 106
     */
107
-    private static $_fileinfoDb;
107
+	private static $_fileinfoDb;
108 108
 
109 109
    /**
110 110
     * Observers attached to the request (instances of SplObserver)
111 111
     * @var  array
112 112
     */
113
-    protected $observers = array();
113
+	protected $observers = array();
114 114
 
115 115
    /**
116 116
     * Request URL
117 117
     * @var  Net_URL2
118 118
     */
119
-    protected $url;
119
+	protected $url;
120 120
 
121 121
    /**
122 122
     * Request method
123 123
     * @var  string
124 124
     */
125
-    protected $method = self::METHOD_GET;
125
+	protected $method = self::METHOD_GET;
126 126
 
127 127
    /**
128 128
     * Authentication data
129 129
     * @var  array
130 130
     * @see  getAuth()
131 131
     */
132
-    protected $auth;
132
+	protected $auth;
133 133
 
134 134
    /**
135 135
     * Request headers
136 136
     * @var  array
137 137
     */
138
-    protected $headers = array();
138
+	protected $headers = array();
139 139
 
140 140
    /**
141 141
     * Configuration parameters
142 142
     * @var  array
143 143
     * @see  setConfig()
144 144
     */
145
-    protected $config = array(
146
-        'adapter'           => 'HTTP_Request2_Adapter_Socket',
147
-        'connect_timeout'   => 10,
148
-        'timeout'           => 0,
149
-        'use_brackets'      => true,
150
-        'protocol_version'  => '1.1',
151
-        'buffer_size'       => 16384,
152
-        'store_body'        => true,
145
+	protected $config = array(
146
+		'adapter'           => 'HTTP_Request2_Adapter_Socket',
147
+		'connect_timeout'   => 10,
148
+		'timeout'           => 0,
149
+		'use_brackets'      => true,
150
+		'protocol_version'  => '1.1',
151
+		'buffer_size'       => 16384,
152
+		'store_body'        => true,
153 153
 
154
-        'proxy_host'        => '',
155
-        'proxy_port'        => '',
156
-        'proxy_user'        => '',
157
-        'proxy_password'    => '',
158
-        'proxy_auth_scheme' => self::AUTH_BASIC,
154
+		'proxy_host'        => '',
155
+		'proxy_port'        => '',
156
+		'proxy_user'        => '',
157
+		'proxy_password'    => '',
158
+		'proxy_auth_scheme' => self::AUTH_BASIC,
159 159
 
160
-        'ssl_verify_peer'   => true,
161
-        'ssl_verify_host'   => true,
162
-        'ssl_cafile'        => null,
163
-        'ssl_capath'        => null,
164
-        'ssl_local_cert'    => null,
165
-        'ssl_passphrase'    => null,
160
+		'ssl_verify_peer'   => true,
161
+		'ssl_verify_host'   => true,
162
+		'ssl_cafile'        => null,
163
+		'ssl_capath'        => null,
164
+		'ssl_local_cert'    => null,
165
+		'ssl_passphrase'    => null,
166 166
 
167
-        'digest_compat_ie'  => false,
167
+		'digest_compat_ie'  => false,
168 168
 
169
-        'follow_redirects'  => false,
170
-        'max_redirects'     => 5,
171
-        'strict_redirects'  => false
172
-    );
169
+		'follow_redirects'  => false,
170
+		'max_redirects'     => 5,
171
+		'strict_redirects'  => false
172
+	);
173 173
 
174 174
    /**
175 175
     * Last event in request / response handling, intended for observers
176 176
     * @var  array
177 177
     * @see  getLastEvent()
178 178
     */
179
-    protected $lastEvent = array(
180
-        'name' => 'start',
181
-        'data' => null
182
-    );
179
+	protected $lastEvent = array(
180
+		'name' => 'start',
181
+		'data' => null
182
+	);
183 183
 
184 184
    /**
185 185
     * Request body
186 186
     * @var  string|resource
187 187
     * @see  setBody()
188 188
     */
189
-    protected $body = '';
189
+	protected $body = '';
190 190
 
191 191
    /**
192 192
     * Array of POST parameters
193 193
     * @var  array
194 194
     */
195
-    protected $postParams = array();
195
+	protected $postParams = array();
196 196
 
197 197
    /**
198 198
     * Array of file uploads (for multipart/form-data POST requests)
199 199
     * @var  array
200 200
     */
201
-    protected $uploads = array();
201
+	protected $uploads = array();
202 202
 
203 203
    /**
204 204
     * Adapter used to perform actual HTTP request
205 205
     * @var  HTTP_Request2_Adapter
206 206
     */
207
-    protected $adapter;
207
+	protected $adapter;
208 208
 
209 209
 
210 210
    /**
@@ -216,19 +216,19 @@  discard block
 block discarded – undo
216 216
     * @param    string              Request method
217 217
     * @param    array               Configuration for this Request instance
218 218
     */
219
-    public function __construct($url = null, $method = self::METHOD_GET, array $config = array())
220
-    {
221
-        $this->setConfig($config);
222
-        if (!empty($url)) {
223
-            $this->setUrl($url);
224
-        }
225
-        if (!empty($method)) {
226
-            $this->setMethod($method);
227
-        }
228
-        $this->setHeader('user-agent', 'HTTP_Request2/0.5.2 ' .
229
-                         '(http://pear.php.net/package/http_request2) ' .
230
-                         'PHP/' . phpversion());
231
-    }
219
+	public function __construct($url = null, $method = self::METHOD_GET, array $config = array())
220
+	{
221
+		$this->setConfig($config);
222
+		if (!empty($url)) {
223
+			$this->setUrl($url);
224
+		}
225
+		if (!empty($method)) {
226
+			$this->setMethod($method);
227
+		}
228
+		$this->setHeader('user-agent', 'HTTP_Request2/0.5.2 ' .
229
+						 '(http://pear.php.net/package/http_request2) ' .
230
+						 'PHP/' . phpversion());
231
+	}
232 232
 
233 233
    /**
234 234
     * Sets the URL for this request
@@ -241,40 +241,40 @@  discard block
 block discarded – undo
241 241
     * @return   HTTP_Request2
242 242
     * @throws   HTTP_Request2_Exception
243 243
     */
244
-    public function setUrl($url)
245
-    {
246
-        if (is_string($url)) {
247
-            $url = new Net_URL2(
248
-                $url, array(Net_URL2::OPTION_USE_BRACKETS => $this->config['use_brackets'])
249
-            );
250
-        }
251
-        if (!$url instanceof Net_URL2) {
252
-            throw new HTTP_Request2_Exception('Parameter is not a valid HTTP URL');
253
-        }
254
-        // URL contains username / password?
255
-        if ($url->getUserinfo()) {
256
-            $username = $url->getUser();
257
-            $password = $url->getPassword();
258
-            $this->setAuth(rawurldecode($username), $password? rawurldecode($password): '');
259
-            $url->setUserinfo('');
260
-        }
261
-        if ('' == $url->getPath()) {
262
-            $url->setPath('/');
263
-        }
264
-        $this->url = $url;
265
-
266
-        return $this;
267
-    }
244
+	public function setUrl($url)
245
+	{
246
+		if (is_string($url)) {
247
+			$url = new Net_URL2(
248
+				$url, array(Net_URL2::OPTION_USE_BRACKETS => $this->config['use_brackets'])
249
+			);
250
+		}
251
+		if (!$url instanceof Net_URL2) {
252
+			throw new HTTP_Request2_Exception('Parameter is not a valid HTTP URL');
253
+		}
254
+		// URL contains username / password?
255
+		if ($url->getUserinfo()) {
256
+			$username = $url->getUser();
257
+			$password = $url->getPassword();
258
+			$this->setAuth(rawurldecode($username), $password? rawurldecode($password): '');
259
+			$url->setUserinfo('');
260
+		}
261
+		if ('' == $url->getPath()) {
262
+			$url->setPath('/');
263
+		}
264
+		$this->url = $url;
265
+
266
+		return $this;
267
+	}
268 268
 
269 269
    /**
270 270
     * Returns the request URL
271 271
     *
272 272
     * @return   Net_URL2
273 273
     */
274
-    public function getUrl()
275
-    {
276
-        return $this->url;
277
-    }
274
+	public function getUrl()
275
+	{
276
+		return $this->url;
277
+	}
278 278
 
279 279
    /**
280 280
     * Sets the request method
@@ -283,26 +283,26 @@  discard block
 block discarded – undo
283 283
     * @return   HTTP_Request2
284 284
     * @throws   HTTP_Request2_Exception if the method name is invalid
285 285
     */
286
-    public function setMethod($method)
287
-    {
288
-        // Method name should be a token: http://tools.ietf.org/html/rfc2616#section-5.1.1
289
-        if (preg_match(self::REGEXP_INVALID_TOKEN, $method)) {
290
-            throw new HTTP_Request2_Exception("Invalid request method '{$method}'");
291
-        }
292
-        $this->method = $method;
286
+	public function setMethod($method)
287
+	{
288
+		// Method name should be a token: http://tools.ietf.org/html/rfc2616#section-5.1.1
289
+		if (preg_match(self::REGEXP_INVALID_TOKEN, $method)) {
290
+			throw new HTTP_Request2_Exception("Invalid request method '{$method}'");
291
+		}
292
+		$this->method = $method;
293 293
 
294
-        return $this;
295
-    }
294
+		return $this;
295
+	}
296 296
 
297 297
    /**
298 298
     * Returns the request method
299 299
     *
300 300
     * @return   string
301 301
     */
302
-    public function getMethod()
303
-    {
304
-        return $this->method;
305
-    }
302
+	public function getMethod()
303
+	{
304
+		return $this->method;
305
+	}
306 306
 
307 307
    /**
308 308
     * Sets the configuration parameter(s)
@@ -352,24 +352,24 @@  discard block
 block discarded – undo
352 352
     * @return   HTTP_Request2
353 353
     * @throws   HTTP_Request2_Exception If the parameter is unknown
354 354
     */
355
-    public function setConfig($nameOrConfig, $value = null)
356
-    {
357
-        if (is_array($nameOrConfig)) {
358
-            foreach ($nameOrConfig as $name => $value) {
359
-                $this->setConfig($name, $value);
360
-            }
355
+	public function setConfig($nameOrConfig, $value = null)
356
+	{
357
+		if (is_array($nameOrConfig)) {
358
+			foreach ($nameOrConfig as $name => $value) {
359
+				$this->setConfig($name, $value);
360
+			}
361 361
 
362
-        } else {
363
-            if (!array_key_exists($nameOrConfig, $this->config)) {
364
-                throw new HTTP_Request2_Exception(
365
-                    "Unknown configuration parameter '{$nameOrConfig}'"
366
-                );
367
-            }
368
-            $this->config[$nameOrConfig] = $value;
369
-        }
362
+		} else {
363
+			if (!array_key_exists($nameOrConfig, $this->config)) {
364
+				throw new HTTP_Request2_Exception(
365
+					"Unknown configuration parameter '{$nameOrConfig}'"
366
+				);
367
+			}
368
+			$this->config[$nameOrConfig] = $value;
369
+		}
370 370
 
371
-        return $this;
372
-    }
371
+		return $this;
372
+	}
373 373
 
374 374
    /**
375 375
     * Returns the value(s) of the configuration parameter(s)
@@ -379,17 +379,17 @@  discard block
 block discarded – undo
379 379
     *                   parameters if $name is not given
380 380
     * @throws   HTTP_Request2_Exception If the parameter is unknown
381 381
     */
382
-    public function getConfig($name = null)
383
-    {
384
-        if (null === $name) {
385
-            return $this->config;
386
-        } elseif (!array_key_exists($name, $this->config)) {
387
-            throw new HTTP_Request2_Exception(
388
-                "Unknown configuration parameter '{$name}'"
389
-            );
390
-        }
391
-        return $this->config[$name];
392
-    }
382
+	public function getConfig($name = null)
383
+	{
384
+		if (null === $name) {
385
+			return $this->config;
386
+		} elseif (!array_key_exists($name, $this->config)) {
387
+			throw new HTTP_Request2_Exception(
388
+				"Unknown configuration parameter '{$name}'"
389
+			);
390
+		}
391
+		return $this->config[$name];
392
+	}
393 393
 
394 394
    /**
395 395
     * Sets the autentification data
@@ -399,20 +399,20 @@  discard block
 block discarded – undo
399 399
     * @param    string  authentication scheme
400 400
     * @return   HTTP_Request2
401 401
     */
402
-    public function setAuth($user, $password = '', $scheme = self::AUTH_BASIC)
403
-    {
404
-        if (empty($user)) {
405
-            $this->auth = null;
406
-        } else {
407
-            $this->auth = array(
408
-                'user'     => (string)$user,
409
-                'password' => (string)$password,
410
-                'scheme'   => $scheme
411
-            );
412
-        }
402
+	public function setAuth($user, $password = '', $scheme = self::AUTH_BASIC)
403
+	{
404
+		if (empty($user)) {
405
+			$this->auth = null;
406
+		} else {
407
+			$this->auth = array(
408
+				'user'     => (string)$user,
409
+				'password' => (string)$password,
410
+				'scheme'   => $scheme
411
+			);
412
+		}
413 413
 
414
-        return $this;
415
-    }
414
+		return $this;
415
+	}
416 416
 
417 417
    /**
418 418
     * Returns the authentication data
@@ -422,10 +422,10 @@  discard block
 block discarded – undo
422 422
     *
423 423
     * @return   array
424 424
     */
425
-    public function getAuth()
426
-    {
427
-        return $this->auth;
428
-    }
425
+	public function getAuth()
426
+	{
427
+		return $this->auth;
428
+	}
429 429
 
430 430
    /**
431 431
     * Sets request header(s)
@@ -451,35 +451,35 @@  discard block
 block discarded – undo
451 451
     * @return   HTTP_Request2
452 452
     * @throws   HTTP_Request2_Exception
453 453
     */
454
-    public function setHeader($name, $value = null)
455
-    {
456
-        if (is_array($name)) {
457
-            foreach ($name as $k => $v) {
458
-                if (is_string($k)) {
459
-                    $this->setHeader($k, $v);
460
-                } else {
461
-                    $this->setHeader($v);
462
-                }
463
-            }
464
-        } else {
465
-            if (null === $value && strpos($name, ':')) {
466
-                list($name, $value) = array_map('trim', explode(':', $name, 2));
467
-            }
468
-            // Header name should be a token: http://tools.ietf.org/html/rfc2616#section-4.2
469
-            if (preg_match(self::REGEXP_INVALID_TOKEN, $name)) {
470
-                throw new HTTP_Request2_Exception("Invalid header name '{$name}'");
471
-            }
472
-            // Header names are case insensitive anyway
473
-            $name = strtolower($name);
474
-            if (null === $value) {
475
-                unset($this->headers[$name]);
476
-            } else {
477
-                $this->headers[$name] = $value;
478
-            }
479
-        }
480
-
481
-        return $this;
482
-    }
454
+	public function setHeader($name, $value = null)
455
+	{
456
+		if (is_array($name)) {
457
+			foreach ($name as $k => $v) {
458
+				if (is_string($k)) {
459
+					$this->setHeader($k, $v);
460
+				} else {
461
+					$this->setHeader($v);
462
+				}
463
+			}
464
+		} else {
465
+			if (null === $value && strpos($name, ':')) {
466
+				list($name, $value) = array_map('trim', explode(':', $name, 2));
467
+			}
468
+			// Header name should be a token: http://tools.ietf.org/html/rfc2616#section-4.2
469
+			if (preg_match(self::REGEXP_INVALID_TOKEN, $name)) {
470
+				throw new HTTP_Request2_Exception("Invalid header name '{$name}'");
471
+			}
472
+			// Header names are case insensitive anyway
473
+			$name = strtolower($name);
474
+			if (null === $value) {
475
+				unset($this->headers[$name]);
476
+			} else {
477
+				$this->headers[$name] = $value;
478
+			}
479
+		}
480
+
481
+		return $this;
482
+	}
483 483
 
484 484
    /**
485 485
     * Returns the request headers
@@ -489,10 +489,10 @@  discard block
 block discarded – undo
489 489
     *
490 490
     * @return   array
491 491
     */
492
-    public function getHeaders()
493
-    {
494
-        return $this->headers;
495
-    }
492
+	public function getHeaders()
493
+	{
494
+		return $this->headers;
495
+	}
496 496
 
497 497
    /**
498 498
     * Appends a cookie to "Cookie:" header
@@ -502,17 +502,17 @@  discard block
 block discarded – undo
502 502
     * @return   HTTP_Request2
503 503
     * @throws   HTTP_Request2_Exception
504 504
     */
505
-    public function addCookie($name, $value)
506
-    {
507
-        $cookie = $name . '=' . $value;
508
-        if (preg_match(self::REGEXP_INVALID_COOKIE, $cookie)) {
509
-            throw new HTTP_Request2_Exception("Invalid cookie: '{$cookie}'");
510
-        }
511
-        $cookies = empty($this->headers['cookie'])? '': $this->headers['cookie'] . '; ';
512
-        $this->setHeader('cookie', $cookies . $cookie);
505
+	public function addCookie($name, $value)
506
+	{
507
+		$cookie = $name . '=' . $value;
508
+		if (preg_match(self::REGEXP_INVALID_COOKIE, $cookie)) {
509
+			throw new HTTP_Request2_Exception("Invalid cookie: '{$cookie}'");
510
+		}
511
+		$cookies = empty($this->headers['cookie'])? '': $this->headers['cookie'] . '; ';
512
+		$this->setHeader('cookie', $cookies . $cookie);
513 513
 
514
-        return $this;
515
-    }
514
+		return $this;
515
+	}
516 516
 
517 517
    /**
518 518
     * Sets the request body
@@ -522,55 +522,55 @@  discard block
 block discarded – undo
522 522
     * @return   HTTP_Request2
523 523
     * @throws   HTTP_Request2_Exception
524 524
     */
525
-    public function setBody($body, $isFilename = false)
526
-    {
527
-        if (!$isFilename) {
528
-            if (!$body instanceof HTTP_Request2_MultipartBody) {
529
-                $this->body = (string)$body;
530
-            } else {
531
-                $this->body = $body;
532
-            }
533
-        } else {
534
-            if (!($fp = @fopen($body, 'rb'))) {
535
-                throw new HTTP_Request2_Exception("Cannot open file {$body}");
536
-            }
537
-            $this->body = $fp;
538
-            if (empty($this->headers['content-type'])) {
539
-                $this->setHeader('content-type', self::detectMimeType($body));
540
-            }
541
-        }
542
-        $this->postParams = $this->uploads = array();
543
-
544
-        return $this;
545
-    }
525
+	public function setBody($body, $isFilename = false)
526
+	{
527
+		if (!$isFilename) {
528
+			if (!$body instanceof HTTP_Request2_MultipartBody) {
529
+				$this->body = (string)$body;
530
+			} else {
531
+				$this->body = $body;
532
+			}
533
+		} else {
534
+			if (!($fp = @fopen($body, 'rb'))) {
535
+				throw new HTTP_Request2_Exception("Cannot open file {$body}");
536
+			}
537
+			$this->body = $fp;
538
+			if (empty($this->headers['content-type'])) {
539
+				$this->setHeader('content-type', self::detectMimeType($body));
540
+			}
541
+		}
542
+		$this->postParams = $this->uploads = array();
543
+
544
+		return $this;
545
+	}
546 546
 
547 547
    /**
548 548
     * Returns the request body
549 549
     *
550 550
     * @return   string|resource|HTTP_Request2_MultipartBody
551 551
     */
552
-    public function getBody()
553
-    {
554
-        if (self::METHOD_POST == $this->method &&
555
-            (!empty($this->postParams) || !empty($this->uploads))
556
-        ) {
557
-            if ('application/x-www-form-urlencoded' == $this->headers['content-type']) {
558
-                $body = http_build_query($this->postParams, '', '&');
559
-                if (!$this->getConfig('use_brackets')) {
560
-                    $body = preg_replace('/%5B\d+%5D=/', '=', $body);
561
-                }
562
-                // support RFC 3986 by not encoding '~' symbol (request #15368)
563
-                return str_replace('%7E', '~', $body);
564
-
565
-            } elseif ('multipart/form-data' == $this->headers['content-type']) {
566
-                require_once 'HTTP/Request2/MultipartBody.php';
567
-                return new HTTP_Request2_MultipartBody(
568
-                    $this->postParams, $this->uploads, $this->getConfig('use_brackets')
569
-                );
570
-            }
571
-        }
572
-        return $this->body;
573
-    }
552
+	public function getBody()
553
+	{
554
+		if (self::METHOD_POST == $this->method &&
555
+			(!empty($this->postParams) || !empty($this->uploads))
556
+		) {
557
+			if ('application/x-www-form-urlencoded' == $this->headers['content-type']) {
558
+				$body = http_build_query($this->postParams, '', '&');
559
+				if (!$this->getConfig('use_brackets')) {
560
+					$body = preg_replace('/%5B\d+%5D=/', '=', $body);
561
+				}
562
+				// support RFC 3986 by not encoding '~' symbol (request #15368)
563
+				return str_replace('%7E', '~', $body);
564
+
565
+			} elseif ('multipart/form-data' == $this->headers['content-type']) {
566
+				require_once 'HTTP/Request2/MultipartBody.php';
567
+				return new HTTP_Request2_MultipartBody(
568
+					$this->postParams, $this->uploads, $this->getConfig('use_brackets')
569
+				);
570
+			}
571
+		}
572
+		return $this->body;
573
+	}
574 574
 
575 575
    /**
576 576
     * Adds a file to form-based file upload
@@ -588,45 +588,45 @@  discard block
 block discarded – undo
588 588
     * @return   HTTP_Request2
589 589
     * @throws   HTTP_Request2_Exception
590 590
     */
591
-    public function addUpload($fieldName, $filename, $sendFilename = null,
592
-                              $contentType = null)
593
-    {
594
-        if (!is_array($filename)) {
595
-            if (!($fp = @fopen($filename, 'rb'))) {
596
-                throw new HTTP_Request2_Exception("Cannot open file {$filename}");
597
-            }
598
-            $this->uploads[$fieldName] = array(
599
-                'fp'        => $fp,
600
-                'filename'  => empty($sendFilename)? basename($filename): $sendFilename,
601
-                'size'      => filesize($filename),
602
-                'type'      => empty($contentType)? self::detectMimeType($filename): $contentType
603
-            );
604
-        } else {
605
-            $fps = $names = $sizes = $types = array();
606
-            foreach ($filename as $f) {
607
-                if (!is_array($f)) {
608
-                    $f = array($f);
609
-                }
610
-                if (!($fp = @fopen($f[0], 'rb'))) {
611
-                    throw new HTTP_Request2_Exception("Cannot open file {$f[0]}");
612
-                }
613
-                $fps[]   = $fp;
614
-                $names[] = empty($f[1])? basename($f[0]): $f[1];
615
-                $sizes[] = filesize($f[0]);
616
-                $types[] = empty($f[2])? self::detectMimeType($f[0]): $f[2];
617
-            }
618
-            $this->uploads[$fieldName] = array(
619
-                'fp' => $fps, 'filename' => $names, 'size' => $sizes, 'type' => $types
620
-            );
621
-        }
622
-        if (empty($this->headers['content-type']) ||
623
-            'application/x-www-form-urlencoded' == $this->headers['content-type']
624
-        ) {
625
-            $this->setHeader('content-type', 'multipart/form-data');
626
-        }
627
-
628
-        return $this;
629
-    }
591
+	public function addUpload($fieldName, $filename, $sendFilename = null,
592
+							  $contentType = null)
593
+	{
594
+		if (!is_array($filename)) {
595
+			if (!($fp = @fopen($filename, 'rb'))) {
596
+				throw new HTTP_Request2_Exception("Cannot open file {$filename}");
597
+			}
598
+			$this->uploads[$fieldName] = array(
599
+				'fp'        => $fp,
600
+				'filename'  => empty($sendFilename)? basename($filename): $sendFilename,
601
+				'size'      => filesize($filename),
602
+				'type'      => empty($contentType)? self::detectMimeType($filename): $contentType
603
+			);
604
+		} else {
605
+			$fps = $names = $sizes = $types = array();
606
+			foreach ($filename as $f) {
607
+				if (!is_array($f)) {
608
+					$f = array($f);
609
+				}
610
+				if (!($fp = @fopen($f[0], 'rb'))) {
611
+					throw new HTTP_Request2_Exception("Cannot open file {$f[0]}");
612
+				}
613
+				$fps[]   = $fp;
614
+				$names[] = empty($f[1])? basename($f[0]): $f[1];
615
+				$sizes[] = filesize($f[0]);
616
+				$types[] = empty($f[2])? self::detectMimeType($f[0]): $f[2];
617
+			}
618
+			$this->uploads[$fieldName] = array(
619
+				'fp' => $fps, 'filename' => $names, 'size' => $sizes, 'type' => $types
620
+			);
621
+		}
622
+		if (empty($this->headers['content-type']) ||
623
+			'application/x-www-form-urlencoded' == $this->headers['content-type']
624
+		) {
625
+			$this->setHeader('content-type', 'multipart/form-data');
626
+		}
627
+
628
+		return $this;
629
+	}
630 630
 
631 631
    /**
632 632
     * Adds POST parameter(s) to the request.
@@ -635,61 +635,61 @@  discard block
 block discarded – undo
635 635
     * @param    mixed           parameter value (can be an array)
636 636
     * @return   HTTP_Request2
637 637
     */
638
-    public function addPostParameter($name, $value = null)
639
-    {
640
-        if (!is_array($name)) {
641
-            $this->postParams[$name] = $value;
642
-        } else {
643
-            foreach ($name as $k => $v) {
644
-                $this->addPostParameter($k, $v);
645
-            }
646
-        }
647
-        if (empty($this->headers['content-type'])) {
648
-            $this->setHeader('content-type', 'application/x-www-form-urlencoded');
649
-        }
638
+	public function addPostParameter($name, $value = null)
639
+	{
640
+		if (!is_array($name)) {
641
+			$this->postParams[$name] = $value;
642
+		} else {
643
+			foreach ($name as $k => $v) {
644
+				$this->addPostParameter($k, $v);
645
+			}
646
+		}
647
+		if (empty($this->headers['content-type'])) {
648
+			$this->setHeader('content-type', 'application/x-www-form-urlencoded');
649
+		}
650 650
 
651
-        return $this;
652
-    }
651
+		return $this;
652
+	}
653 653
 
654 654
    /**
655 655
     * Attaches a new observer
656 656
     *
657 657
     * @param    SplObserver
658 658
     */
659
-    public function attach(SplObserver $observer)
660
-    {
661
-        foreach ($this->observers as $attached) {
662
-            if ($attached === $observer) {
663
-                return;
664
-            }
665
-        }
666
-        $this->observers[] = $observer;
667
-    }
659
+	public function attach(SplObserver $observer)
660
+	{
661
+		foreach ($this->observers as $attached) {
662
+			if ($attached === $observer) {
663
+				return;
664
+			}
665
+		}
666
+		$this->observers[] = $observer;
667
+	}
668 668
 
669 669
    /**
670 670
     * Detaches an existing observer
671 671
     *
672 672
     * @param    SplObserver
673 673
     */
674
-    public function detach(SplObserver $observer)
675
-    {
676
-        foreach ($this->observers as $key => $attached) {
677
-            if ($attached === $observer) {
678
-                unset($this->observers[$key]);
679
-                return;
680
-            }
681
-        }
682
-    }
674
+	public function detach(SplObserver $observer)
675
+	{
676
+		foreach ($this->observers as $key => $attached) {
677
+			if ($attached === $observer) {
678
+				unset($this->observers[$key]);
679
+				return;
680
+			}
681
+		}
682
+	}
683 683
 
684 684
    /**
685 685
     * Notifies all observers
686 686
     */
687
-    public function notify()
688
-    {
689
-        foreach ($this->observers as $observer) {
690
-            $observer->update($this);
691
-        }
692
-    }
687
+	public function notify()
688
+	{
689
+		foreach ($this->observers as $observer) {
690
+			$observer->update($this);
691
+		}
692
+	}
693 693
 
694 694
    /**
695 695
     * Sets the last event
@@ -700,14 +700,14 @@  discard block
 block discarded – undo
700 700
     * @param    string  event name
701 701
     * @param    mixed   event data
702 702
     */
703
-    public function setLastEvent($name, $data = null)
704
-    {
705
-        $this->lastEvent = array(
706
-            'name' => $name,
707
-            'data' => $data
708
-        );
709
-        $this->notify();
710
-    }
703
+	public function setLastEvent($name, $data = null)
704
+	{
705
+		$this->lastEvent = array(
706
+			'name' => $name,
707
+			'data' => $data
708
+		);
709
+		$this->notify();
710
+	}
711 711
 
712 712
    /**
713 713
     * Returns the last event
@@ -736,10 +736,10 @@  discard block
 block discarded – undo
736 736
     *
737 737
     * @return   array   The array has two keys: 'name' and 'data'
738 738
     */
739
-    public function getLastEvent()
740
-    {
741
-        return $this->lastEvent;
742
-    }
739
+	public function getLastEvent()
740
+	{
741
+		return $this->lastEvent;
742
+	}
743 743
 
744 744
    /**
745 745
     * Sets the adapter used to actually perform the request
@@ -757,29 +757,29 @@  discard block
 block discarded – undo
757 757
     * @return   HTTP_Request2
758 758
     * @throws   HTTP_Request2_Exception
759 759
     */
760
-    public function setAdapter($adapter)
761
-    {
762
-        if (is_string($adapter)) {
763
-            if (!class_exists($adapter, false)) {
764
-                if (false === strpos($adapter, '_')) {
765
-                    $adapter = 'HTTP_Request2_Adapter_' . ucfirst($adapter);
766
-                }
767
-                if (preg_match('/^HTTP_Request2_Adapter_([a-zA-Z0-9]+)$/', $adapter)) {
768
-                    include_once str_replace('_', DIRECTORY_SEPARATOR, $adapter) . '.php';
769
-                }
770
-                if (!class_exists($adapter, false)) {
771
-                    throw new HTTP_Request2_Exception("Class {$adapter} not found");
772
-                }
773
-            }
774
-            $adapter = new $adapter;
775
-        }
776
-        if (!$adapter instanceof HTTP_Request2_Adapter) {
777
-            throw new HTTP_Request2_Exception('Parameter is not a HTTP request adapter');
778
-        }
779
-        $this->adapter = $adapter;
780
-
781
-        return $this;
782
-    }
760
+	public function setAdapter($adapter)
761
+	{
762
+		if (is_string($adapter)) {
763
+			if (!class_exists($adapter, false)) {
764
+				if (false === strpos($adapter, '_')) {
765
+					$adapter = 'HTTP_Request2_Adapter_' . ucfirst($adapter);
766
+				}
767
+				if (preg_match('/^HTTP_Request2_Adapter_([a-zA-Z0-9]+)$/', $adapter)) {
768
+					include_once str_replace('_', DIRECTORY_SEPARATOR, $adapter) . '.php';
769
+				}
770
+				if (!class_exists($adapter, false)) {
771
+					throw new HTTP_Request2_Exception("Class {$adapter} not found");
772
+				}
773
+			}
774
+			$adapter = new $adapter;
775
+		}
776
+		if (!$adapter instanceof HTTP_Request2_Adapter) {
777
+			throw new HTTP_Request2_Exception('Parameter is not a HTTP request adapter');
778
+		}
779
+		$this->adapter = $adapter;
780
+
781
+		return $this;
782
+	}
783 783
 
784 784
    /**
785 785
     * Sends the request and returns the response
@@ -787,48 +787,48 @@  discard block
 block discarded – undo
787 787
     * @throws   HTTP_Request2_Exception
788 788
     * @return   HTTP_Request2_Response
789 789
     */
790
-    public function send()
791
-    {
792
-        // Sanity check for URL
793
-        if (!$this->url instanceof Net_URL2) {
794
-            throw new HTTP_Request2_Exception('No URL given');
795
-        } elseif (!$this->url->isAbsolute()) {
796
-            throw new HTTP_Request2_Exception('Absolute URL required');
797
-        } elseif (!in_array(strtolower($this->url->getScheme()), array('https', 'http'))) {
798
-            throw new HTTP_Request2_Exception('Not a HTTP URL');
799
-        }
800
-        if (empty($this->adapter)) {
801
-            $this->setAdapter($this->getConfig('adapter'));
802
-        }
803
-        // magic_quotes_runtime may break file uploads and chunked response
804
-        // processing; see bug #4543. Don't use ini_get() here; see bug #16440.
805
-        if ($magicQuotes = get_magic_quotes_runtime()) {
806
-            set_magic_quotes_runtime(false);
807
-        }
808
-        // force using single byte encoding if mbstring extension overloads
809
-        // strlen() and substr(); see bug #1781, bug #10605
810
-        if (extension_loaded('mbstring') && (2 & ini_get('mbstring.func_overload'))) {
811
-            $oldEncoding = mb_internal_encoding();
812
-            mb_internal_encoding('iso-8859-1');
813
-        }
814
-
815
-        try {
816
-            $response = $this->adapter->sendRequest($this);
817
-        } catch (Exception $e) {
818
-        }
819
-        // cleanup in either case (poor man's "finally" clause)
820
-        if ($magicQuotes) {
821
-            set_magic_quotes_runtime(true);
822
-        }
823
-        if (!empty($oldEncoding)) {
824
-            mb_internal_encoding($oldEncoding);
825
-        }
826
-        // rethrow the exception
827
-        if (!empty($e)) {
828
-            throw $e;
829
-        }
830
-        return $response;
831
-    }
790
+	public function send()
791
+	{
792
+		// Sanity check for URL
793
+		if (!$this->url instanceof Net_URL2) {
794
+			throw new HTTP_Request2_Exception('No URL given');
795
+		} elseif (!$this->url->isAbsolute()) {
796
+			throw new HTTP_Request2_Exception('Absolute URL required');
797
+		} elseif (!in_array(strtolower($this->url->getScheme()), array('https', 'http'))) {
798
+			throw new HTTP_Request2_Exception('Not a HTTP URL');
799
+		}
800
+		if (empty($this->adapter)) {
801
+			$this->setAdapter($this->getConfig('adapter'));
802
+		}
803
+		// magic_quotes_runtime may break file uploads and chunked response
804
+		// processing; see bug #4543. Don't use ini_get() here; see bug #16440.
805
+		if ($magicQuotes = get_magic_quotes_runtime()) {
806
+			set_magic_quotes_runtime(false);
807
+		}
808
+		// force using single byte encoding if mbstring extension overloads
809
+		// strlen() and substr(); see bug #1781, bug #10605
810
+		if (extension_loaded('mbstring') && (2 & ini_get('mbstring.func_overload'))) {
811
+			$oldEncoding = mb_internal_encoding();
812
+			mb_internal_encoding('iso-8859-1');
813
+		}
814
+
815
+		try {
816
+			$response = $this->adapter->sendRequest($this);
817
+		} catch (Exception $e) {
818
+		}
819
+		// cleanup in either case (poor man's "finally" clause)
820
+		if ($magicQuotes) {
821
+			set_magic_quotes_runtime(true);
822
+		}
823
+		if (!empty($oldEncoding)) {
824
+			mb_internal_encoding($oldEncoding);
825
+		}
826
+		// rethrow the exception
827
+		if (!empty($e)) {
828
+			throw $e;
829
+		}
830
+		return $response;
831
+	}
832 832
 
833 833
    /**
834 834
     * Tries to detect MIME type of a file
@@ -840,22 +840,22 @@  discard block
 block discarded – undo
840 840
     * @param    string  filename
841 841
     * @return   string  file MIME type
842 842
     */
843
-    protected static function detectMimeType($filename)
844
-    {
845
-        // finfo extension from PECL available
846
-        if (function_exists('finfo_open')) {
847
-            if (!isset(self::$_fileinfoDb)) {
848
-                self::$_fileinfoDb = @finfo_open(FILEINFO_MIME);
849
-            }
850
-            if (self::$_fileinfoDb) {
851
-                $info = finfo_file(self::$_fileinfoDb, $filename);
852
-            }
853
-        }
854
-        // (deprecated) mime_content_type function available
855
-        if (empty($info) && function_exists('mime_content_type')) {
856
-            return mime_content_type($filename);
857
-        }
858
-        return empty($info)? 'application/octet-stream': $info;
859
-    }
843
+	protected static function detectMimeType($filename)
844
+	{
845
+		// finfo extension from PECL available
846
+		if (function_exists('finfo_open')) {
847
+			if (!isset(self::$_fileinfoDb)) {
848
+				self::$_fileinfoDb = @finfo_open(FILEINFO_MIME);
849
+			}
850
+			if (self::$_fileinfoDb) {
851
+				$info = finfo_file(self::$_fileinfoDb, $filename);
852
+			}
853
+		}
854
+		// (deprecated) mime_content_type function available
855
+		if (empty($info) && function_exists('mime_content_type')) {
856
+			return mime_content_type($filename);
857
+		}
858
+		return empty($info)? 'application/octet-stream': $info;
859
+	}
860 860
 }
861 861
 ?>
862 862
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -225,9 +225,9 @@  discard block
 block discarded – undo
225 225
         if (!empty($method)) {
226 226
             $this->setMethod($method);
227 227
         }
228
-        $this->setHeader('user-agent', 'HTTP_Request2/0.5.2 ' .
229
-                         '(http://pear.php.net/package/http_request2) ' .
230
-                         'PHP/' . phpversion());
228
+        $this->setHeader('user-agent', 'HTTP_Request2/0.5.2 '.
229
+                         '(http://pear.php.net/package/http_request2) '.
230
+                         'PHP/'.phpversion());
231 231
     }
232 232
 
233 233
    /**
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
         if ($url->getUserinfo()) {
256 256
             $username = $url->getUser();
257 257
             $password = $url->getPassword();
258
-            $this->setAuth(rawurldecode($username), $password? rawurldecode($password): '');
258
+            $this->setAuth(rawurldecode($username), $password ? rawurldecode($password) : '');
259 259
             $url->setUserinfo('');
260 260
         }
261 261
         if ('' == $url->getPath()) {
@@ -405,8 +405,8 @@  discard block
 block discarded – undo
405 405
             $this->auth = null;
406 406
         } else {
407 407
             $this->auth = array(
408
-                'user'     => (string)$user,
409
-                'password' => (string)$password,
408
+                'user'     => (string) $user,
409
+                'password' => (string) $password,
410 410
                 'scheme'   => $scheme
411 411
             );
412 412
         }
@@ -504,12 +504,12 @@  discard block
 block discarded – undo
504 504
     */
505 505
     public function addCookie($name, $value)
506 506
     {
507
-        $cookie = $name . '=' . $value;
507
+        $cookie = $name.'='.$value;
508 508
         if (preg_match(self::REGEXP_INVALID_COOKIE, $cookie)) {
509 509
             throw new HTTP_Request2_Exception("Invalid cookie: '{$cookie}'");
510 510
         }
511
-        $cookies = empty($this->headers['cookie'])? '': $this->headers['cookie'] . '; ';
512
-        $this->setHeader('cookie', $cookies . $cookie);
511
+        $cookies = empty($this->headers['cookie']) ? '' : $this->headers['cookie'].'; ';
512
+        $this->setHeader('cookie', $cookies.$cookie);
513 513
 
514 514
         return $this;
515 515
     }
@@ -526,7 +526,7 @@  discard block
 block discarded – undo
526 526
     {
527 527
         if (!$isFilename) {
528 528
             if (!$body instanceof HTTP_Request2_MultipartBody) {
529
-                $this->body = (string)$body;
529
+                $this->body = (string) $body;
530 530
             } else {
531 531
                 $this->body = $body;
532 532
             }
@@ -597,9 +597,9 @@  discard block
 block discarded – undo
597 597
             }
598 598
             $this->uploads[$fieldName] = array(
599 599
                 'fp'        => $fp,
600
-                'filename'  => empty($sendFilename)? basename($filename): $sendFilename,
600
+                'filename'  => empty($sendFilename) ? basename($filename) : $sendFilename,
601 601
                 'size'      => filesize($filename),
602
-                'type'      => empty($contentType)? self::detectMimeType($filename): $contentType
602
+                'type'      => empty($contentType) ? self::detectMimeType($filename) : $contentType
603 603
             );
604 604
         } else {
605 605
             $fps = $names = $sizes = $types = array();
@@ -611,9 +611,9 @@  discard block
 block discarded – undo
611 611
                     throw new HTTP_Request2_Exception("Cannot open file {$f[0]}");
612 612
                 }
613 613
                 $fps[]   = $fp;
614
-                $names[] = empty($f[1])? basename($f[0]): $f[1];
614
+                $names[] = empty($f[1]) ? basename($f[0]) : $f[1];
615 615
                 $sizes[] = filesize($f[0]);
616
-                $types[] = empty($f[2])? self::detectMimeType($f[0]): $f[2];
616
+                $types[] = empty($f[2]) ? self::detectMimeType($f[0]) : $f[2];
617 617
             }
618 618
             $this->uploads[$fieldName] = array(
619 619
                 'fp' => $fps, 'filename' => $names, 'size' => $sizes, 'type' => $types
@@ -762,10 +762,10 @@  discard block
 block discarded – undo
762 762
         if (is_string($adapter)) {
763 763
             if (!class_exists($adapter, false)) {
764 764
                 if (false === strpos($adapter, '_')) {
765
-                    $adapter = 'HTTP_Request2_Adapter_' . ucfirst($adapter);
765
+                    $adapter = 'HTTP_Request2_Adapter_'.ucfirst($adapter);
766 766
                 }
767 767
                 if (preg_match('/^HTTP_Request2_Adapter_([a-zA-Z0-9]+)$/', $adapter)) {
768
-                    include_once str_replace('_', DIRECTORY_SEPARATOR, $adapter) . '.php';
768
+                    include_once str_replace('_', DIRECTORY_SEPARATOR, $adapter).'.php';
769 769
                 }
770 770
                 if (!class_exists($adapter, false)) {
771 771
                     throw new HTTP_Request2_Exception("Class {$adapter} not found");
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
         if (empty($info) && function_exists('mime_content_type')) {
856 856
             return mime_content_type($filename);
857 857
         }
858
-        return empty($info)? 'application/octet-stream': $info;
858
+        return empty($info) ? 'application/octet-stream' : $info;
859 859
     }
860 860
 }
861 861
 ?>
862 862
\ No newline at end of file
Please login to merge, or discard this patch.
libs/PEAR.1.9/HTTP/Request2/Adapter/Curl.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
     * Callback function called by cURL for saving the response headers
380 380
     *
381 381
     * @param    resource    cURL handle
382
-    * @param    string      response header (with trailing CRLF)
382
+    * @param    string      string header (with trailing CRLF)
383 383
     * @return   integer     number of bytes saved
384 384
     * @see      HTTP_Request2_Response::parseHeaderLine()
385 385
     */
@@ -440,7 +440,7 @@  discard block
 block discarded – undo
440 440
     * Callback function called by cURL for saving the response body
441 441
     *
442 442
     * @param    resource    cURL handle (not used)
443
-    * @param    string      part of the response body
443
+    * @param    string      string of the response body
444 444
     * @return   integer     number of bytes saved
445 445
     * @see      HTTP_Request2_Response::appendBody()
446 446
     */
Please login to merge, or discard this patch.
Indentation   +306 added lines, -306 removed lines patch added patch discarded remove patch
@@ -60,55 +60,55 @@  discard block
 block discarded – undo
60 60
     * Mapping of header names to cURL options
61 61
     * @var  array
62 62
     */
63
-    protected static $headerMap = array(
64
-        'accept-encoding' => CURLOPT_ENCODING,
65
-        'cookie'          => CURLOPT_COOKIE,
66
-        'referer'         => CURLOPT_REFERER,
67
-        'user-agent'      => CURLOPT_USERAGENT
68
-    );
63
+	protected static $headerMap = array(
64
+		'accept-encoding' => CURLOPT_ENCODING,
65
+		'cookie'          => CURLOPT_COOKIE,
66
+		'referer'         => CURLOPT_REFERER,
67
+		'user-agent'      => CURLOPT_USERAGENT
68
+	);
69 69
 
70 70
    /**
71 71
     * Mapping of SSL context options to cURL options
72 72
     * @var  array
73 73
     */
74
-    protected static $sslContextMap = array(
75
-        'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER,
76
-        'ssl_cafile'      => CURLOPT_CAINFO,
77
-        'ssl_capath'      => CURLOPT_CAPATH,
78
-        'ssl_local_cert'  => CURLOPT_SSLCERT,
79
-        'ssl_passphrase'  => CURLOPT_SSLCERTPASSWD
74
+	protected static $sslContextMap = array(
75
+		'ssl_verify_peer' => CURLOPT_SSL_VERIFYPEER,
76
+		'ssl_cafile'      => CURLOPT_CAINFO,
77
+		'ssl_capath'      => CURLOPT_CAPATH,
78
+		'ssl_local_cert'  => CURLOPT_SSLCERT,
79
+		'ssl_passphrase'  => CURLOPT_SSLCERTPASSWD
80 80
    );
81 81
 
82 82
    /**
83 83
     * Response being received
84 84
     * @var  HTTP_Request2_Response
85 85
     */
86
-    protected $response;
86
+	protected $response;
87 87
 
88 88
    /**
89 89
     * Whether 'sentHeaders' event was sent to observers
90 90
     * @var  boolean
91 91
     */
92
-    protected $eventSentHeaders = false;
92
+	protected $eventSentHeaders = false;
93 93
 
94 94
    /**
95 95
     * Whether 'receivedHeaders' event was sent to observers
96 96
     * @var boolean
97 97
     */
98
-    protected $eventReceivedHeaders = false;
98
+	protected $eventReceivedHeaders = false;
99 99
 
100 100
    /**
101 101
     * Position within request body
102 102
     * @var  integer
103 103
     * @see  callbackReadBody()
104 104
     */
105
-    protected $position = 0;
105
+	protected $position = 0;
106 106
 
107 107
    /**
108 108
     * Information about last transfer, as returned by curl_getinfo()
109 109
     * @var  array
110 110
     */
111
-    protected $lastInfo;
111
+	protected $lastInfo;
112 112
 
113 113
    /**
114 114
     * Sends request to the remote server and returns its response
@@ -117,52 +117,52 @@  discard block
 block discarded – undo
117 117
     * @return   HTTP_Request2_Response
118 118
     * @throws   HTTP_Request2_Exception
119 119
     */
120
-    public function sendRequest(HTTP_Request2 $request)
121
-    {
122
-        if (!extension_loaded('curl')) {
123
-            throw new HTTP_Request2_Exception('cURL extension not available');
124
-        }
125
-
126
-        $this->request              = $request;
127
-        $this->response             = null;
128
-        $this->position             = 0;
129
-        $this->eventSentHeaders     = false;
130
-        $this->eventReceivedHeaders = false;
131
-
132
-        try {
133
-            if (false === curl_exec($ch = $this->createCurlHandle())) {
134
-                $errorMessage = 'Error sending request: #' . curl_errno($ch) .
135
-                                                       ' ' . curl_error($ch);
136
-            }
137
-        } catch (Exception $e) {
138
-        }
139
-        $this->lastInfo = curl_getinfo($ch);
140
-        curl_close($ch);
141
-
142
-        $response = $this->response;
143
-        unset($this->request, $this->requestBody, $this->response);
144
-
145
-        if (!empty($e)) {
146
-            throw $e;
147
-        } elseif (!empty($errorMessage)) {
148
-            throw new HTTP_Request2_Exception($errorMessage);
149
-        }
150
-
151
-        if (0 < $this->lastInfo['size_download']) {
152
-            $request->setLastEvent('receivedBody', $response);
153
-        }
154
-        return $response;
155
-    }
120
+	public function sendRequest(HTTP_Request2 $request)
121
+	{
122
+		if (!extension_loaded('curl')) {
123
+			throw new HTTP_Request2_Exception('cURL extension not available');
124
+		}
125
+
126
+		$this->request              = $request;
127
+		$this->response             = null;
128
+		$this->position             = 0;
129
+		$this->eventSentHeaders     = false;
130
+		$this->eventReceivedHeaders = false;
131
+
132
+		try {
133
+			if (false === curl_exec($ch = $this->createCurlHandle())) {
134
+				$errorMessage = 'Error sending request: #' . curl_errno($ch) .
135
+													   ' ' . curl_error($ch);
136
+			}
137
+		} catch (Exception $e) {
138
+		}
139
+		$this->lastInfo = curl_getinfo($ch);
140
+		curl_close($ch);
141
+
142
+		$response = $this->response;
143
+		unset($this->request, $this->requestBody, $this->response);
144
+
145
+		if (!empty($e)) {
146
+			throw $e;
147
+		} elseif (!empty($errorMessage)) {
148
+			throw new HTTP_Request2_Exception($errorMessage);
149
+		}
150
+
151
+		if (0 < $this->lastInfo['size_download']) {
152
+			$request->setLastEvent('receivedBody', $response);
153
+		}
154
+		return $response;
155
+	}
156 156
 
157 157
    /**
158 158
     * Returns information about last transfer
159 159
     *
160 160
     * @return   array   associative array as returned by curl_getinfo()
161 161
     */
162
-    public function getInfo()
163
-    {
164
-        return $this->lastInfo;
165
-    }
162
+	public function getInfo()
163
+	{
164
+		return $this->lastInfo;
165
+	}
166 166
 
167 167
    /**
168 168
     * Creates a new cURL handle and populates it with data from the request
@@ -170,140 +170,140 @@  discard block
 block discarded – undo
170 170
     * @return   resource    a cURL handle, as created by curl_init()
171 171
     * @throws   HTTP_Request2_Exception
172 172
     */
173
-    protected function createCurlHandle()
174
-    {
175
-        $ch = curl_init();
176
-
177
-        curl_setopt_array($ch, array(
178
-            // setup write callbacks
179
-            CURLOPT_HEADERFUNCTION => array($this, 'callbackWriteHeader'),
180
-            CURLOPT_WRITEFUNCTION  => array($this, 'callbackWriteBody'),
181
-            // buffer size
182
-            CURLOPT_BUFFERSIZE     => $this->request->getConfig('buffer_size'),
183
-            // connection timeout
184
-            CURLOPT_CONNECTTIMEOUT => $this->request->getConfig('connect_timeout'),
185
-            // save full outgoing headers, in case someone is interested
186
-            CURLINFO_HEADER_OUT    => true,
187
-            // request url
188
-            CURLOPT_URL            => $this->request->getUrl()->getUrl()
189
-        ));
190
-
191
-        // set up redirects
192
-        if (!$this->request->getConfig('follow_redirects')) {
193
-            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
194
-        } else {
195
-            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
196
-            curl_setopt($ch, CURLOPT_MAXREDIRS, $this->request->getConfig('max_redirects'));
197
-            // limit redirects to http(s), works in 5.2.10+
198
-            if (defined('CURLOPT_REDIR_PROTOCOLS')) {
199
-                curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
200
-            }
201
-            // works sometime after 5.3.0, http://bugs.php.net/bug.php?id=49571
202
-            if ($this->request->getConfig('strict_redirects') && defined('CURLOPT_POSTREDIR ')) {
203
-                curl_setopt($ch, CURLOPT_POSTREDIR, 3);
204
-            }
205
-        }
206
-
207
-        // request timeout
208
-        if ($timeout = $this->request->getConfig('timeout')) {
209
-            curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
210
-        }
211
-
212
-        // set HTTP version
213
-        switch ($this->request->getConfig('protocol_version')) {
214
-            case '1.0':
215
-                curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
216
-                break;
217
-            case '1.1':
218
-                curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
219
-        }
220
-
221
-        // set request method
222
-        switch ($this->request->getMethod()) {
223
-            case HTTP_Request2::METHOD_GET:
224
-                curl_setopt($ch, CURLOPT_HTTPGET, true);
225
-                break;
226
-            case HTTP_Request2::METHOD_POST:
227
-                curl_setopt($ch, CURLOPT_POST, true);
228
-                break;
229
-            case HTTP_Request2::METHOD_HEAD:
230
-                curl_setopt($ch, CURLOPT_NOBODY, true);
231
-                break;
232
-            default:
233
-                curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->request->getMethod());
234
-        }
235
-
236
-        // set proxy, if needed
237
-        if ($host = $this->request->getConfig('proxy_host')) {
238
-            if (!($port = $this->request->getConfig('proxy_port'))) {
239
-                throw new HTTP_Request2_Exception('Proxy port not provided');
240
-            }
241
-            curl_setopt($ch, CURLOPT_PROXY, $host . ':' . $port);
242
-            if ($user = $this->request->getConfig('proxy_user')) {
243
-                curl_setopt($ch, CURLOPT_PROXYUSERPWD, $user . ':' .
244
-                            $this->request->getConfig('proxy_password'));
245
-                switch ($this->request->getConfig('proxy_auth_scheme')) {
246
-                    case HTTP_Request2::AUTH_BASIC:
247
-                        curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
248
-                        break;
249
-                    case HTTP_Request2::AUTH_DIGEST:
250
-                        curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST);
251
-                }
252
-            }
253
-        }
254
-
255
-        // set authentication data
256
-        if ($auth = $this->request->getAuth()) {
257
-            curl_setopt($ch, CURLOPT_USERPWD, $auth['user'] . ':' . $auth['password']);
258
-            switch ($auth['scheme']) {
259
-                case HTTP_Request2::AUTH_BASIC:
260
-                    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
261
-                    break;
262
-                case HTTP_Request2::AUTH_DIGEST:
263
-                    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
264
-            }
265
-        }
266
-
267
-        // set SSL options
268
-        if (0 == strcasecmp($this->request->getUrl()->getScheme(), 'https')) {
269
-            foreach ($this->request->getConfig() as $name => $value) {
270
-                if ('ssl_verify_host' == $name && null !== $value) {
271
-                    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $value? 2: 0);
272
-                } elseif (isset(self::$sslContextMap[$name]) && null !== $value) {
273
-                    curl_setopt($ch, self::$sslContextMap[$name], $value);
274
-                }
275
-            }
276
-        }
277
-
278
-        $headers = $this->request->getHeaders();
279
-        // make cURL automagically send proper header
280
-        if (!isset($headers['accept-encoding'])) {
281
-            $headers['accept-encoding'] = '';
282
-        }
283
-
284
-        // set headers having special cURL keys
285
-        foreach (self::$headerMap as $name => $option) {
286
-            if (isset($headers[$name])) {
287
-                curl_setopt($ch, $option, $headers[$name]);
288
-                unset($headers[$name]);
289
-            }
290
-        }
291
-
292
-        $this->calculateRequestLength($headers);
293
-        if (isset($headers['content-length'])) {
294
-            $this->workaroundPhpBug47204($ch, $headers);
295
-        }
296
-
297
-        // set headers not having special keys
298
-        $headersFmt = array();
299
-        foreach ($headers as $name => $value) {
300
-            $canonicalName = implode('-', array_map('ucfirst', explode('-', $name)));
301
-            $headersFmt[]  = $canonicalName . ': ' . $value;
302
-        }
303
-        curl_setopt($ch, CURLOPT_HTTPHEADER, $headersFmt);
304
-
305
-        return $ch;
306
-    }
173
+	protected function createCurlHandle()
174
+	{
175
+		$ch = curl_init();
176
+
177
+		curl_setopt_array($ch, array(
178
+			// setup write callbacks
179
+			CURLOPT_HEADERFUNCTION => array($this, 'callbackWriteHeader'),
180
+			CURLOPT_WRITEFUNCTION  => array($this, 'callbackWriteBody'),
181
+			// buffer size
182
+			CURLOPT_BUFFERSIZE     => $this->request->getConfig('buffer_size'),
183
+			// connection timeout
184
+			CURLOPT_CONNECTTIMEOUT => $this->request->getConfig('connect_timeout'),
185
+			// save full outgoing headers, in case someone is interested
186
+			CURLINFO_HEADER_OUT    => true,
187
+			// request url
188
+			CURLOPT_URL            => $this->request->getUrl()->getUrl()
189
+		));
190
+
191
+		// set up redirects
192
+		if (!$this->request->getConfig('follow_redirects')) {
193
+			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
194
+		} else {
195
+			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
196
+			curl_setopt($ch, CURLOPT_MAXREDIRS, $this->request->getConfig('max_redirects'));
197
+			// limit redirects to http(s), works in 5.2.10+
198
+			if (defined('CURLOPT_REDIR_PROTOCOLS')) {
199
+				curl_setopt($ch, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
200
+			}
201
+			// works sometime after 5.3.0, http://bugs.php.net/bug.php?id=49571
202
+			if ($this->request->getConfig('strict_redirects') && defined('CURLOPT_POSTREDIR ')) {
203
+				curl_setopt($ch, CURLOPT_POSTREDIR, 3);
204
+			}
205
+		}
206
+
207
+		// request timeout
208
+		if ($timeout = $this->request->getConfig('timeout')) {
209
+			curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
210
+		}
211
+
212
+		// set HTTP version
213
+		switch ($this->request->getConfig('protocol_version')) {
214
+			case '1.0':
215
+				curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
216
+				break;
217
+			case '1.1':
218
+				curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
219
+		}
220
+
221
+		// set request method
222
+		switch ($this->request->getMethod()) {
223
+			case HTTP_Request2::METHOD_GET:
224
+				curl_setopt($ch, CURLOPT_HTTPGET, true);
225
+				break;
226
+			case HTTP_Request2::METHOD_POST:
227
+				curl_setopt($ch, CURLOPT_POST, true);
228
+				break;
229
+			case HTTP_Request2::METHOD_HEAD:
230
+				curl_setopt($ch, CURLOPT_NOBODY, true);
231
+				break;
232
+			default:
233
+				curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->request->getMethod());
234
+		}
235
+
236
+		// set proxy, if needed
237
+		if ($host = $this->request->getConfig('proxy_host')) {
238
+			if (!($port = $this->request->getConfig('proxy_port'))) {
239
+				throw new HTTP_Request2_Exception('Proxy port not provided');
240
+			}
241
+			curl_setopt($ch, CURLOPT_PROXY, $host . ':' . $port);
242
+			if ($user = $this->request->getConfig('proxy_user')) {
243
+				curl_setopt($ch, CURLOPT_PROXYUSERPWD, $user . ':' .
244
+							$this->request->getConfig('proxy_password'));
245
+				switch ($this->request->getConfig('proxy_auth_scheme')) {
246
+					case HTTP_Request2::AUTH_BASIC:
247
+						curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
248
+						break;
249
+					case HTTP_Request2::AUTH_DIGEST:
250
+						curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_DIGEST);
251
+				}
252
+			}
253
+		}
254
+
255
+		// set authentication data
256
+		if ($auth = $this->request->getAuth()) {
257
+			curl_setopt($ch, CURLOPT_USERPWD, $auth['user'] . ':' . $auth['password']);
258
+			switch ($auth['scheme']) {
259
+				case HTTP_Request2::AUTH_BASIC:
260
+					curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
261
+					break;
262
+				case HTTP_Request2::AUTH_DIGEST:
263
+					curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
264
+			}
265
+		}
266
+
267
+		// set SSL options
268
+		if (0 == strcasecmp($this->request->getUrl()->getScheme(), 'https')) {
269
+			foreach ($this->request->getConfig() as $name => $value) {
270
+				if ('ssl_verify_host' == $name && null !== $value) {
271
+					curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $value? 2: 0);
272
+				} elseif (isset(self::$sslContextMap[$name]) && null !== $value) {
273
+					curl_setopt($ch, self::$sslContextMap[$name], $value);
274
+				}
275
+			}
276
+		}
277
+
278
+		$headers = $this->request->getHeaders();
279
+		// make cURL automagically send proper header
280
+		if (!isset($headers['accept-encoding'])) {
281
+			$headers['accept-encoding'] = '';
282
+		}
283
+
284
+		// set headers having special cURL keys
285
+		foreach (self::$headerMap as $name => $option) {
286
+			if (isset($headers[$name])) {
287
+				curl_setopt($ch, $option, $headers[$name]);
288
+				unset($headers[$name]);
289
+			}
290
+		}
291
+
292
+		$this->calculateRequestLength($headers);
293
+		if (isset($headers['content-length'])) {
294
+			$this->workaroundPhpBug47204($ch, $headers);
295
+		}
296
+
297
+		// set headers not having special keys
298
+		$headersFmt = array();
299
+		foreach ($headers as $name => $value) {
300
+			$canonicalName = implode('-', array_map('ucfirst', explode('-', $name)));
301
+			$headersFmt[]  = $canonicalName . ': ' . $value;
302
+		}
303
+		curl_setopt($ch, CURLOPT_HTTPHEADER, $headersFmt);
304
+
305
+		return $ch;
306
+	}
307 307
 
308 308
    /**
309 309
     * Workaround for PHP bug #47204 that prevents rewinding request body
@@ -315,32 +315,32 @@  discard block
 block discarded – undo
315 315
     * @param    resource    cURL handle
316 316
     * @param    array       Request headers
317 317
     */
318
-    protected function workaroundPhpBug47204($ch, &$headers)
319
-    {
320
-        // no redirects, no digest auth -> probably no rewind needed
321
-        if (!$this->request->getConfig('follow_redirects')
322
-            && (!($auth = $this->request->getAuth())
323
-                || HTTP_Request2::AUTH_DIGEST != $auth['scheme'])
324
-        ) {
325
-            curl_setopt($ch, CURLOPT_READFUNCTION, array($this, 'callbackReadBody'));
326
-
327
-        // rewind may be needed, read the whole body into memory
328
-        } else {
329
-            if ($this->requestBody instanceof HTTP_Request2_MultipartBody) {
330
-                $this->requestBody = $this->requestBody->__toString();
331
-
332
-            } elseif (is_resource($this->requestBody)) {
333
-                $fp = $this->requestBody;
334
-                $this->requestBody = '';
335
-                while (!feof($fp)) {
336
-                    $this->requestBody .= fread($fp, 16384);
337
-                }
338
-            }
339
-            // curl hangs up if content-length is present
340
-            unset($headers['content-length']);
341
-            curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody);
342
-        }
343
-    }
318
+	protected function workaroundPhpBug47204($ch, &$headers)
319
+	{
320
+		// no redirects, no digest auth -> probably no rewind needed
321
+		if (!$this->request->getConfig('follow_redirects')
322
+			&& (!($auth = $this->request->getAuth())
323
+				|| HTTP_Request2::AUTH_DIGEST != $auth['scheme'])
324
+		) {
325
+			curl_setopt($ch, CURLOPT_READFUNCTION, array($this, 'callbackReadBody'));
326
+
327
+		// rewind may be needed, read the whole body into memory
328
+		} else {
329
+			if ($this->requestBody instanceof HTTP_Request2_MultipartBody) {
330
+				$this->requestBody = $this->requestBody->__toString();
331
+
332
+			} elseif (is_resource($this->requestBody)) {
333
+				$fp = $this->requestBody;
334
+				$this->requestBody = '';
335
+				while (!feof($fp)) {
336
+					$this->requestBody .= fread($fp, 16384);
337
+				}
338
+			}
339
+			// curl hangs up if content-length is present
340
+			unset($headers['content-length']);
341
+			curl_setopt($ch, CURLOPT_POSTFIELDS, $this->requestBody);
342
+		}
343
+	}
344 344
 
345 345
    /**
346 346
     * Callback function called by cURL for reading the request body
@@ -350,30 +350,30 @@  discard block
 block discarded – undo
350 350
     * @param    integer     maximum length of data to return
351 351
     * @return   string      part of the request body, up to $length bytes
352 352
     */
353
-    protected function callbackReadBody($ch, $fd, $length)
354
-    {
355
-        if (!$this->eventSentHeaders) {
356
-            $this->request->setLastEvent(
357
-                'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT)
358
-            );
359
-            $this->eventSentHeaders = true;
360
-        }
361
-        if (in_array($this->request->getMethod(), self::$bodyDisallowed) ||
362
-            0 == $this->contentLength || $this->position >= $this->contentLength
363
-        ) {
364
-            return '';
365
-        }
366
-        if (is_string($this->requestBody)) {
367
-            $string = substr($this->requestBody, $this->position, $length);
368
-        } elseif (is_resource($this->requestBody)) {
369
-            $string = fread($this->requestBody, $length);
370
-        } else {
371
-            $string = $this->requestBody->read($length);
372
-        }
373
-        $this->request->setLastEvent('sentBodyPart', strlen($string));
374
-        $this->position += strlen($string);
375
-        return $string;
376
-    }
353
+	protected function callbackReadBody($ch, $fd, $length)
354
+	{
355
+		if (!$this->eventSentHeaders) {
356
+			$this->request->setLastEvent(
357
+				'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT)
358
+			);
359
+			$this->eventSentHeaders = true;
360
+		}
361
+		if (in_array($this->request->getMethod(), self::$bodyDisallowed) ||
362
+			0 == $this->contentLength || $this->position >= $this->contentLength
363
+		) {
364
+			return '';
365
+		}
366
+		if (is_string($this->requestBody)) {
367
+			$string = substr($this->requestBody, $this->position, $length);
368
+		} elseif (is_resource($this->requestBody)) {
369
+			$string = fread($this->requestBody, $length);
370
+		} else {
371
+			$string = $this->requestBody->read($length);
372
+		}
373
+		$this->request->setLastEvent('sentBodyPart', strlen($string));
374
+		$this->position += strlen($string);
375
+		return $string;
376
+	}
377 377
 
378 378
    /**
379 379
     * Callback function called by cURL for saving the response headers
@@ -383,58 +383,58 @@  discard block
 block discarded – undo
383 383
     * @return   integer     number of bytes saved
384 384
     * @see      HTTP_Request2_Response::parseHeaderLine()
385 385
     */
386
-    protected function callbackWriteHeader($ch, $string)
387
-    {
388
-        // we may receive a second set of headers if doing e.g. digest auth
389
-        if ($this->eventReceivedHeaders || !$this->eventSentHeaders) {
390
-            // don't bother with 100-Continue responses (bug #15785)
391
-            if (!$this->eventSentHeaders ||
392
-                $this->response->getStatus() >= 200
393
-            ) {
394
-                $this->request->setLastEvent(
395
-                    'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT)
396
-                );
397
-            }
398
-            $upload = curl_getinfo($ch, CURLINFO_SIZE_UPLOAD);
399
-            // if body wasn't read by a callback, send event with total body size
400
-            if ($upload > $this->position) {
401
-                $this->request->setLastEvent(
402
-                    'sentBodyPart', $upload - $this->position
403
-                );
404
-                $this->position = $upload;
405
-            }
406
-            $this->eventSentHeaders = true;
407
-            // we'll need a new response object
408
-            if ($this->eventReceivedHeaders) {
409
-                $this->eventReceivedHeaders = false;
410
-                $this->response             = null;
411
-            }
412
-        }
413
-        if (empty($this->response)) {
414
-            $this->response = new HTTP_Request2_Response($string, false);
415
-        } else {
416
-            $this->response->parseHeaderLine($string);
417
-            if ('' == trim($string)) {
418
-                // don't bother with 100-Continue responses (bug #15785)
419
-                if (200 <= $this->response->getStatus()) {
420
-                    $this->request->setLastEvent('receivedHeaders', $this->response);
421
-                }
422
-                // for versions lower than 5.2.10, check the redirection URL protocol
423
-                if ($this->request->getConfig('follow_redirects') && !defined('CURLOPT_REDIR_PROTOCOLS')
424
-                    && $this->response->isRedirect()
425
-                ) {
426
-                    $redirectUrl = new Net_URL2($this->response->getHeader('location'));
427
-                    if ($redirectUrl->isAbsolute()
428
-                        && !in_array($redirectUrl->getScheme(), array('http', 'https'))
429
-                    ) {
430
-                        return -1;
431
-                    }
432
-                }
433
-                $this->eventReceivedHeaders = true;
434
-            }
435
-        }
436
-        return strlen($string);
437
-    }
386
+	protected function callbackWriteHeader($ch, $string)
387
+	{
388
+		// we may receive a second set of headers if doing e.g. digest auth
389
+		if ($this->eventReceivedHeaders || !$this->eventSentHeaders) {
390
+			// don't bother with 100-Continue responses (bug #15785)
391
+			if (!$this->eventSentHeaders ||
392
+				$this->response->getStatus() >= 200
393
+			) {
394
+				$this->request->setLastEvent(
395
+					'sentHeaders', curl_getinfo($ch, CURLINFO_HEADER_OUT)
396
+				);
397
+			}
398
+			$upload = curl_getinfo($ch, CURLINFO_SIZE_UPLOAD);
399
+			// if body wasn't read by a callback, send event with total body size
400
+			if ($upload > $this->position) {
401
+				$this->request->setLastEvent(
402
+					'sentBodyPart', $upload - $this->position
403
+				);
404
+				$this->position = $upload;
405
+			}
406
+			$this->eventSentHeaders = true;
407
+			// we'll need a new response object
408
+			if ($this->eventReceivedHeaders) {
409
+				$this->eventReceivedHeaders = false;
410
+				$this->response             = null;
411
+			}
412
+		}
413
+		if (empty($this->response)) {
414
+			$this->response = new HTTP_Request2_Response($string, false);
415
+		} else {
416
+			$this->response->parseHeaderLine($string);
417
+			if ('' == trim($string)) {
418
+				// don't bother with 100-Continue responses (bug #15785)
419
+				if (200 <= $this->response->getStatus()) {
420
+					$this->request->setLastEvent('receivedHeaders', $this->response);
421
+				}
422
+				// for versions lower than 5.2.10, check the redirection URL protocol
423
+				if ($this->request->getConfig('follow_redirects') && !defined('CURLOPT_REDIR_PROTOCOLS')
424
+					&& $this->response->isRedirect()
425
+				) {
426
+					$redirectUrl = new Net_URL2($this->response->getHeader('location'));
427
+					if ($redirectUrl->isAbsolute()
428
+						&& !in_array($redirectUrl->getScheme(), array('http', 'https'))
429
+					) {
430
+						return -1;
431
+					}
432
+				}
433
+				$this->eventReceivedHeaders = true;
434
+			}
435
+		}
436
+		return strlen($string);
437
+	}
438 438
 
439 439
    /**
440 440
     * Callback function called by cURL for saving the response body
@@ -444,18 +444,18 @@  discard block
 block discarded – undo
444 444
     * @return   integer     number of bytes saved
445 445
     * @see      HTTP_Request2_Response::appendBody()
446 446
     */
447
-    protected function callbackWriteBody($ch, $string)
448
-    {
449
-        // cURL calls WRITEFUNCTION callback without calling HEADERFUNCTION if
450
-        // response doesn't start with proper HTTP status line (see bug #15716)
451
-        if (empty($this->response)) {
452
-            throw new HTTP_Request2_Exception("Malformed response: {$string}");
453
-        }
454
-        if ($this->request->getConfig('store_body')) {
455
-            $this->response->appendBody($string);
456
-        }
457
-        $this->request->setLastEvent('receivedBodyPart', $string);
458
-        return strlen($string);
459
-    }
447
+	protected function callbackWriteBody($ch, $string)
448
+	{
449
+		// cURL calls WRITEFUNCTION callback without calling HEADERFUNCTION if
450
+		// response doesn't start with proper HTTP status line (see bug #15716)
451
+		if (empty($this->response)) {
452
+			throw new HTTP_Request2_Exception("Malformed response: {$string}");
453
+		}
454
+		if ($this->request->getConfig('store_body')) {
455
+			$this->response->appendBody($string);
456
+		}
457
+		$this->request->setLastEvent('receivedBodyPart', $string);
458
+		return strlen($string);
459
+	}
460 460
 }
461 461
 ?>
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 
132 132
         try {
133 133
             if (false === curl_exec($ch = $this->createCurlHandle())) {
134
-                $errorMessage = 'Error sending request: #' . curl_errno($ch) .
135
-                                                       ' ' . curl_error($ch);
134
+                $errorMessage = 'Error sending request: #'.curl_errno($ch).
135
+                                                       ' '.curl_error($ch);
136 136
             }
137 137
         } catch (Exception $e) {
138 138
         }
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
             if (!($port = $this->request->getConfig('proxy_port'))) {
239 239
                 throw new HTTP_Request2_Exception('Proxy port not provided');
240 240
             }
241
-            curl_setopt($ch, CURLOPT_PROXY, $host . ':' . $port);
241
+            curl_setopt($ch, CURLOPT_PROXY, $host.':'.$port);
242 242
             if ($user = $this->request->getConfig('proxy_user')) {
243
-                curl_setopt($ch, CURLOPT_PROXYUSERPWD, $user . ':' .
243
+                curl_setopt($ch, CURLOPT_PROXYUSERPWD, $user.':'.
244 244
                             $this->request->getConfig('proxy_password'));
245 245
                 switch ($this->request->getConfig('proxy_auth_scheme')) {
246 246
                     case HTTP_Request2::AUTH_BASIC:
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 
255 255
         // set authentication data
256 256
         if ($auth = $this->request->getAuth()) {
257
-            curl_setopt($ch, CURLOPT_USERPWD, $auth['user'] . ':' . $auth['password']);
257
+            curl_setopt($ch, CURLOPT_USERPWD, $auth['user'].':'.$auth['password']);
258 258
             switch ($auth['scheme']) {
259 259
                 case HTTP_Request2::AUTH_BASIC:
260 260
                     curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
         if (0 == strcasecmp($this->request->getUrl()->getScheme(), 'https')) {
269 269
             foreach ($this->request->getConfig() as $name => $value) {
270 270
                 if ('ssl_verify_host' == $name && null !== $value) {
271
-                    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $value? 2: 0);
271
+                    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $value ? 2 : 0);
272 272
                 } elseif (isset(self::$sslContextMap[$name]) && null !== $value) {
273 273
                     curl_setopt($ch, self::$sslContextMap[$name], $value);
274 274
                 }
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
         $headersFmt = array();
299 299
         foreach ($headers as $name => $value) {
300 300
             $canonicalName = implode('-', array_map('ucfirst', explode('-', $name)));
301
-            $headersFmt[]  = $canonicalName . ': ' . $value;
301
+            $headersFmt[]  = $canonicalName.': '.$value;
302 302
         }
303 303
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headersFmt);
304 304
 
Please login to merge, or discard this patch.
libs/PEAR.1.9/Net/URL2.php 3 patches
Doc Comments   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
      * Returns the user part of the userinfo part (the part preceding the first
230 230
      *  ":"), or false if there is no userinfo part.
231 231
      *
232
-     * @return  string|bool
232
+     * @return  string|false
233 233
      */
234 234
     public function getUser()
235 235
     {
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      * contain "@" in front of the hostname) or the userinfo part does not
245 245
      * contain ":".
246 246
      *
247
-     * @return  string|bool
247
+     * @return  string|false
248 248
      */
249 249
     public function getPassword()
250 250
     {
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
      * @param string|bool $userinfo userinfo or username
272 272
      * @param string|bool $password optional password, or false
273 273
      *
274
-     * @return void
274
+     * @return Net_URL2
275 275
      */
276 276
     public function setUserinfo($userinfo, $password = false)
277 277
     {
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
      * Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or
334 334
      * false if there is no authority.
335 335
      *
336
-     * @return string|bool
336
+     * @return false|string
337 337
      */
338 338
     public function getAuthority()
339 339
     {
@@ -360,11 +360,11 @@  discard block
 block discarded – undo
360 360
      * Sets the authority part, i.e. [ userinfo "@" ] host [ ":" port ]. Specify
361 361
      * false if there is no authority.
362 362
      *
363
-     * @param string|false $authority a hostname or an IP addresse, possibly
363
+     * @param string|boolean $authority a hostname or an IP addresse, possibly
364 364
      *                                with userinfo prefixed and port number
365 365
      *                                appended, e.g. "foo:[email protected]:81".
366 366
      *
367
-     * @return void
367
+     * @return Net_URL2
368 368
      */
369 369
     public function setAuthority($authority)
370 370
     {
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
      *
518 518
      * @param array $array (name => value) array
519 519
      *
520
-     * @return void
520
+     * @return Net_URL2
521 521
      */
522 522
     public function setQueryVariables(array $array)
523 523
     {
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
      * @param string $name  variable name
553 553
      * @param mixed  $value variable value
554 554
      *
555
-     * @return  array
555
+     * @return  Net_URL2
556 556
      */
557 557
     public function setQueryVariable($name, $value)
558 558
     {
@@ -689,7 +689,7 @@  discard block
 block discarded – undo
689 689
      * Returns an Net_URL2 instance representing an absolute URL relative to
690 690
      * this URL.
691 691
      *
692
-     * @param Net_URL2|string $reference relative URL
692
+     * @param Net_URL2 $reference relative URL
693 693
      *
694 694
      * @return Net_URL2
695 695
      */
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
      * Returns a Net_URL2 instance representing the canonical URL of the
827 827
      * currently executing PHP script.
828 828
      * 
829
-     * @return  string
829
+     * @return  Net_URL2
830 830
      */
831 831
     public static function getCanonical()
832 832
     {
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
      *
885 885
      * @param string $optionName The name of the option to retrieve
886 886
      *
887
-     * @return  mixed
887
+     * @return  string
888 888
      */
889 889
     function getOption($optionName)
890 890
     {
Please login to merge, or discard this patch.
Indentation   +828 added lines, -828 removed lines patch added patch discarded remove patch
@@ -56,839 +56,839 @@
 block discarded – undo
56 56
  */
57 57
 class Net_URL2
58 58
 {
59
-    /**
60
-     * Do strict parsing in resolve() (see RFC 3986, section 5.2.2). Default
61
-     * is true.
62
-     */
63
-    const OPTION_STRICT = 'strict';
64
-
65
-    /**
66
-     * Represent arrays in query using PHP's [] notation. Default is true.
67
-     */
68
-    const OPTION_USE_BRACKETS = 'use_brackets';
69
-
70
-    /**
71
-     * URL-encode query variable keys. Default is true.
72
-     */
73
-    const OPTION_ENCODE_KEYS = 'encode_keys';
74
-
75
-    /**
76
-     * Query variable separators when parsing the query string. Every character
77
-     * is considered a separator. Default is "&".
78
-     */
79
-    const OPTION_SEPARATOR_INPUT = 'input_separator';
80
-
81
-    /**
82
-     * Query variable separator used when generating the query string. Default
83
-     * is "&".
84
-     */
85
-    const OPTION_SEPARATOR_OUTPUT = 'output_separator';
86
-
87
-    /**
88
-     * Default options corresponds to how PHP handles $_GET.
89
-     */
90
-    private $_options = array(
91
-        self::OPTION_STRICT           => true,
92
-        self::OPTION_USE_BRACKETS     => true,
93
-        self::OPTION_ENCODE_KEYS      => true,
94
-        self::OPTION_SEPARATOR_INPUT  => '&',
95
-        self::OPTION_SEPARATOR_OUTPUT => '&',
96
-        );
97
-
98
-    /**
99
-     * @var  string|bool
100
-     */
101
-    private $_scheme = false;
102
-
103
-    /**
104
-     * @var  string|bool
105
-     */
106
-    private $_userinfo = false;
107
-
108
-    /**
109
-     * @var  string|bool
110
-     */
111
-    private $_host = false;
112
-
113
-    /**
114
-     * @var  string|bool
115
-     */
116
-    private $_port = false;
117
-
118
-    /**
119
-     * @var  string
120
-     */
121
-    private $_path = '';
122
-
123
-    /**
124
-     * @var  string|bool
125
-     */
126
-    private $_query = false;
127
-
128
-    /**
129
-     * @var  string|bool
130
-     */
131
-    private $_fragment = false;
132
-
133
-    /**
134
-     * Constructor.
135
-     *
136
-     * @param string $url     an absolute or relative URL
137
-     * @param array  $options an array of OPTION_xxx constants
138
-     */
139
-    public function __construct($url, array $options = array())
140
-    {
141
-        foreach ($options as $optionName => $value) {
142
-            if (array_key_exists($optionName, $this->_options)) {
143
-                $this->_options[$optionName] = $value;
144
-            }
145
-        }
146
-
147
-        // The regular expression is copied verbatim from RFC 3986, appendix B.
148
-        // The expression does not validate the URL but matches any string.
149
-        preg_match('!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?!',
150
-                   $url,
151
-                   $matches);
152
-
153
-        // "path" is always present (possibly as an empty string); the rest
154
-        // are optional.
155
-        $this->_scheme = !empty($matches[1]) ? $matches[2] : false;
156
-        $this->setAuthority(!empty($matches[3]) ? $matches[4] : false);
157
-        $this->_path = $matches[5];
158
-        $this->_query = !empty($matches[6]) ? $matches[7] : false;
159
-        $this->_fragment = !empty($matches[8]) ? $matches[9] : false;
160
-    }
161
-
162
-    /**
163
-     * Magic Setter.
164
-     *
165
-     * This method will magically set the value of a private variable ($var)
166
-     * with the value passed as the args
167
-     *
168
-     * @param  string $var      The private variable to set.
169
-     * @param  mixed  $arg      An argument of any type.
170
-     * @return void
171
-     */
172
-    public function __set($var, $arg)
173
-    {
174
-        $method = 'set' . $var;
175
-        if (method_exists($this, $method)) {
176
-            $this->$method($arg);
177
-        }
178
-    }
59
+	/**
60
+	 * Do strict parsing in resolve() (see RFC 3986, section 5.2.2). Default
61
+	 * is true.
62
+	 */
63
+	const OPTION_STRICT = 'strict';
64
+
65
+	/**
66
+	 * Represent arrays in query using PHP's [] notation. Default is true.
67
+	 */
68
+	const OPTION_USE_BRACKETS = 'use_brackets';
69
+
70
+	/**
71
+	 * URL-encode query variable keys. Default is true.
72
+	 */
73
+	const OPTION_ENCODE_KEYS = 'encode_keys';
74
+
75
+	/**
76
+	 * Query variable separators when parsing the query string. Every character
77
+	 * is considered a separator. Default is "&".
78
+	 */
79
+	const OPTION_SEPARATOR_INPUT = 'input_separator';
80
+
81
+	/**
82
+	 * Query variable separator used when generating the query string. Default
83
+	 * is "&".
84
+	 */
85
+	const OPTION_SEPARATOR_OUTPUT = 'output_separator';
86
+
87
+	/**
88
+	 * Default options corresponds to how PHP handles $_GET.
89
+	 */
90
+	private $_options = array(
91
+		self::OPTION_STRICT           => true,
92
+		self::OPTION_USE_BRACKETS     => true,
93
+		self::OPTION_ENCODE_KEYS      => true,
94
+		self::OPTION_SEPARATOR_INPUT  => '&',
95
+		self::OPTION_SEPARATOR_OUTPUT => '&',
96
+		);
97
+
98
+	/**
99
+	 * @var  string|bool
100
+	 */
101
+	private $_scheme = false;
102
+
103
+	/**
104
+	 * @var  string|bool
105
+	 */
106
+	private $_userinfo = false;
107
+
108
+	/**
109
+	 * @var  string|bool
110
+	 */
111
+	private $_host = false;
112
+
113
+	/**
114
+	 * @var  string|bool
115
+	 */
116
+	private $_port = false;
117
+
118
+	/**
119
+	 * @var  string
120
+	 */
121
+	private $_path = '';
122
+
123
+	/**
124
+	 * @var  string|bool
125
+	 */
126
+	private $_query = false;
127
+
128
+	/**
129
+	 * @var  string|bool
130
+	 */
131
+	private $_fragment = false;
132
+
133
+	/**
134
+	 * Constructor.
135
+	 *
136
+	 * @param string $url     an absolute or relative URL
137
+	 * @param array  $options an array of OPTION_xxx constants
138
+	 */
139
+	public function __construct($url, array $options = array())
140
+	{
141
+		foreach ($options as $optionName => $value) {
142
+			if (array_key_exists($optionName, $this->_options)) {
143
+				$this->_options[$optionName] = $value;
144
+			}
145
+		}
146
+
147
+		// The regular expression is copied verbatim from RFC 3986, appendix B.
148
+		// The expression does not validate the URL but matches any string.
149
+		preg_match('!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?!',
150
+				   $url,
151
+				   $matches);
152
+
153
+		// "path" is always present (possibly as an empty string); the rest
154
+		// are optional.
155
+		$this->_scheme = !empty($matches[1]) ? $matches[2] : false;
156
+		$this->setAuthority(!empty($matches[3]) ? $matches[4] : false);
157
+		$this->_path = $matches[5];
158
+		$this->_query = !empty($matches[6]) ? $matches[7] : false;
159
+		$this->_fragment = !empty($matches[8]) ? $matches[9] : false;
160
+	}
161
+
162
+	/**
163
+	 * Magic Setter.
164
+	 *
165
+	 * This method will magically set the value of a private variable ($var)
166
+	 * with the value passed as the args
167
+	 *
168
+	 * @param  string $var      The private variable to set.
169
+	 * @param  mixed  $arg      An argument of any type.
170
+	 * @return void
171
+	 */
172
+	public function __set($var, $arg)
173
+	{
174
+		$method = 'set' . $var;
175
+		if (method_exists($this, $method)) {
176
+			$this->$method($arg);
177
+		}
178
+	}
179 179
     
180
-    /**
181
-     * Magic Getter.
182
-     *
183
-     * This is the magic get method to retrieve the private variable 
184
-     * that was set by either __set() or it's setter...
185
-     * 
186
-     * @param  string $var         The property name to retrieve.
187
-     * @return mixed  $this->$var  Either a boolean false if the
188
-     *                             property is not set or the value
189
-     *                             of the private property.
190
-     */
191
-    public function __get($var)
192
-    {
193
-        $method = 'get' . $var;
194
-        if (method_exists($this, $method)) {
195
-            return $this->$method();
196
-        }
180
+	/**
181
+	 * Magic Getter.
182
+	 *
183
+	 * This is the magic get method to retrieve the private variable 
184
+	 * that was set by either __set() or it's setter...
185
+	 * 
186
+	 * @param  string $var         The property name to retrieve.
187
+	 * @return mixed  $this->$var  Either a boolean false if the
188
+	 *                             property is not set or the value
189
+	 *                             of the private property.
190
+	 */
191
+	public function __get($var)
192
+	{
193
+		$method = 'get' . $var;
194
+		if (method_exists($this, $method)) {
195
+			return $this->$method();
196
+		}
197 197
         
198
-        return false;
199
-    }
198
+		return false;
199
+	}
200 200
     
201
-    /**
202
-     * Returns the scheme, e.g. "http" or "urn", or false if there is no
203
-     * scheme specified, i.e. if this is a relative URL.
204
-     *
205
-     * @return  string|bool
206
-     */
207
-    public function getScheme()
208
-    {
209
-        return $this->_scheme;
210
-    }
211
-
212
-    /**
213
-     * Sets the scheme, e.g. "http" or "urn". Specify false if there is no
214
-     * scheme specified, i.e. if this is a relative URL.
215
-     *
216
-     * @param string|bool $scheme e.g. "http" or "urn", or false if there is no
217
-     *                            scheme specified, i.e. if this is a relative
218
-     *                            URL
219
-     *
220
-     * @return void
221
-     * @see    getScheme()
222
-     */
223
-    public function setScheme($scheme)
224
-    {
225
-        $this->_scheme = $scheme;
226
-    }
227
-
228
-    /**
229
-     * Returns the user part of the userinfo part (the part preceding the first
230
-     *  ":"), or false if there is no userinfo part.
231
-     *
232
-     * @return  string|bool
233
-     */
234
-    public function getUser()
235
-    {
236
-        return $this->_userinfo !== false
237
-            ? preg_replace('@:.*$@', '', $this->_userinfo)
238
-            : false;
239
-    }
240
-
241
-    /**
242
-     * Returns the password part of the userinfo part (the part after the first
243
-     *  ":"), or false if there is no userinfo part (i.e. the URL does not
244
-     * contain "@" in front of the hostname) or the userinfo part does not
245
-     * contain ":".
246
-     *
247
-     * @return  string|bool
248
-     */
249
-    public function getPassword()
250
-    {
251
-        return $this->_userinfo !== false
252
-            ? substr(strstr($this->_userinfo, ':'), 1)
253
-            : false;
254
-    }
255
-
256
-    /**
257
-     * Returns the userinfo part, or false if there is none, i.e. if the
258
-     * authority part does not contain "@".
259
-     *
260
-     * @return  string|bool
261
-     */
262
-    public function getUserinfo()
263
-    {
264
-        return $this->_userinfo;
265
-    }
266
-
267
-    /**
268
-     * Sets the userinfo part. If two arguments are passed, they are combined
269
-     * in the userinfo part as username ":" password.
270
-     *
271
-     * @param string|bool $userinfo userinfo or username
272
-     * @param string|bool $password optional password, or false
273
-     *
274
-     * @return void
275
-     */
276
-    public function setUserinfo($userinfo, $password = false)
277
-    {
278
-        $this->_userinfo = $userinfo;
279
-        if ($password !== false) {
280
-            $this->_userinfo .= ':' . $password;
281
-        }
282
-    }
283
-
284
-    /**
285
-     * Returns the host part, or false if there is no authority part, e.g.
286
-     * relative URLs.
287
-     *
288
-     * @return  string|bool a hostname, an IP address, or false
289
-     */
290
-    public function getHost()
291
-    {
292
-        return $this->_host;
293
-    }
294
-
295
-    /**
296
-     * Sets the host part. Specify false if there is no authority part, e.g.
297
-     * relative URLs.
298
-     *
299
-     * @param string|bool $host a hostname, an IP address, or false
300
-     *
301
-     * @return void
302
-     */
303
-    public function setHost($host)
304
-    {
305
-        $this->_host = $host;
306
-    }
307
-
308
-    /**
309
-     * Returns the port number, or false if there is no port number specified,
310
-     * i.e. if the default port is to be used.
311
-     *
312
-     * @return  string|bool
313
-     */
314
-    public function getPort()
315
-    {
316
-        return $this->_port;
317
-    }
318
-
319
-    /**
320
-     * Sets the port number. Specify false if there is no port number specified,
321
-     * i.e. if the default port is to be used.
322
-     *
323
-     * @param string|bool $port a port number, or false
324
-     *
325
-     * @return void
326
-     */
327
-    public function setPort($port)
328
-    {
329
-        $this->_port = $port;
330
-    }
331
-
332
-    /**
333
-     * Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or
334
-     * false if there is no authority.
335
-     *
336
-     * @return string|bool
337
-     */
338
-    public function getAuthority()
339
-    {
340
-        if (!$this->_host) {
341
-            return false;
342
-        }
343
-
344
-        $authority = '';
345
-
346
-        if ($this->_userinfo !== false) {
347
-            $authority .= $this->_userinfo . '@';
348
-        }
349
-
350
-        $authority .= $this->_host;
351
-
352
-        if ($this->_port !== false) {
353
-            $authority .= ':' . $this->_port;
354
-        }
355
-
356
-        return $authority;
357
-    }
358
-
359
-    /**
360
-     * Sets the authority part, i.e. [ userinfo "@" ] host [ ":" port ]. Specify
361
-     * false if there is no authority.
362
-     *
363
-     * @param string|false $authority a hostname or an IP addresse, possibly
364
-     *                                with userinfo prefixed and port number
365
-     *                                appended, e.g. "foo:[email protected]:81".
366
-     *
367
-     * @return void
368
-     */
369
-    public function setAuthority($authority)
370
-    {
371
-        $this->_userinfo = false;
372
-        $this->_host     = false;
373
-        $this->_port     = false;
374
-        if (preg_match('@^(([^\@]*)\@)?([^:]+)(:(\d*))?$@', $authority, $reg)) {
375
-            if ($reg[1]) {
376
-                $this->_userinfo = $reg[2];
377
-            }
378
-
379
-            $this->_host = $reg[3];
380
-            if (isset($reg[5])) {
381
-                $this->_port = $reg[5];
382
-            }
383
-        }
384
-    }
385
-
386
-    /**
387
-     * Returns the path part (possibly an empty string).
388
-     *
389
-     * @return string
390
-     */
391
-    public function getPath()
392
-    {
393
-        return $this->_path;
394
-    }
395
-
396
-    /**
397
-     * Sets the path part (possibly an empty string).
398
-     *
399
-     * @param string $path a path
400
-     *
401
-     * @return void
402
-     */
403
-    public function setPath($path)
404
-    {
405
-        $this->_path = $path;
406
-    }
407
-
408
-    /**
409
-     * Returns the query string (excluding the leading "?"), or false if "?"
410
-     * is not present in the URL.
411
-     *
412
-     * @return  string|bool
413
-     * @see     self::getQueryVariables()
414
-     */
415
-    public function getQuery()
416
-    {
417
-        return $this->_query;
418
-    }
419
-
420
-    /**
421
-     * Sets the query string (excluding the leading "?"). Specify false if "?"
422
-     * is not present in the URL.
423
-     *
424
-     * @param string|bool $query a query string, e.g. "foo=1&bar=2"
425
-     *
426
-     * @return void
427
-     * @see   self::setQueryVariables()
428
-     */
429
-    public function setQuery($query)
430
-    {
431
-        $this->_query = $query;
432
-    }
433
-
434
-    /**
435
-     * Returns the fragment name, or false if "#" is not present in the URL.
436
-     *
437
-     * @return  string|bool
438
-     */
439
-    public function getFragment()
440
-    {
441
-        return $this->_fragment;
442
-    }
443
-
444
-    /**
445
-     * Sets the fragment name. Specify false if "#" is not present in the URL.
446
-     *
447
-     * @param string|bool $fragment a fragment excluding the leading "#", or
448
-     *                              false
449
-     *
450
-     * @return void
451
-     */
452
-    public function setFragment($fragment)
453
-    {
454
-        $this->_fragment = $fragment;
455
-    }
456
-
457
-    /**
458
-     * Returns the query string like an array as the variables would appear in
459
-     * $_GET in a PHP script. If the URL does not contain a "?", an empty array
460
-     * is returned.
461
-     *
462
-     * @return  array
463
-     */
464
-    public function getQueryVariables()
465
-    {
466
-        $pattern = '/[' .
467
-                   preg_quote($this->getOption(self::OPTION_SEPARATOR_INPUT), '/') .
468
-                   ']/';
469
-        $parts   = preg_split($pattern, $this->_query, -1, PREG_SPLIT_NO_EMPTY);
470
-        $return  = array();
471
-
472
-        foreach ($parts as $part) {
473
-            if (strpos($part, '=') !== false) {
474
-                list($key, $value) = explode('=', $part, 2);
475
-            } else {
476
-                $key   = $part;
477
-                $value = null;
478
-            }
479
-
480
-            if ($this->getOption(self::OPTION_ENCODE_KEYS)) {
481
-                $key = rawurldecode($key);
482
-            }
483
-            $value = rawurldecode($value);
484
-
485
-            if ($this->getOption(self::OPTION_USE_BRACKETS) &&
486
-                preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) {
487
-
488
-                $key = $matches[1];
489
-                $idx = $matches[2];
490
-
491
-                // Ensure is an array
492
-                if (empty($return[$key]) || !is_array($return[$key])) {
493
-                    $return[$key] = array();
494
-                }
495
-
496
-                // Add data
497
-                if ($idx === '') {
498
-                    $return[$key][] = $value;
499
-                } else {
500
-                    $return[$key][$idx] = $value;
501
-                }
502
-            } elseif (!$this->getOption(self::OPTION_USE_BRACKETS)
503
-                      && !empty($return[$key])
504
-            ) {
505
-                $return[$key]   = (array) $return[$key];
506
-                $return[$key][] = $value;
507
-            } else {
508
-                $return[$key] = $value;
509
-            }
510
-        }
511
-
512
-        return $return;
513
-    }
514
-
515
-    /**
516
-     * Sets the query string to the specified variable in the query string.
517
-     *
518
-     * @param array $array (name => value) array
519
-     *
520
-     * @return void
521
-     */
522
-    public function setQueryVariables(array $array)
523
-    {
524
-        if (!$array) {
525
-            $this->_query = false;
526
-        } else {
527
-            foreach ($array as $name => $value) {
528
-                if ($this->getOption(self::OPTION_ENCODE_KEYS)) {
529
-                    $name = self::urlencode($name);
530
-                }
531
-
532
-                if (is_array($value)) {
533
-                    foreach ($value as $k => $v) {
534
-                        $parts[] = $this->getOption(self::OPTION_USE_BRACKETS)
535
-                            ? sprintf('%s[%s]=%s', $name, $k, $v)
536
-                            : ($name . '=' . $v);
537
-                    }
538
-                } elseif (!is_null($value)) {
539
-                    $parts[] = $name . '=' . self::urlencode($value);
540
-                } else {
541
-                    $parts[] = $name;
542
-                }
543
-            }
544
-            $this->_query = implode($this->getOption(self::OPTION_SEPARATOR_OUTPUT),
545
-                                    $parts);
546
-        }
547
-    }
548
-
549
-    /**
550
-     * Sets the specified variable in the query string.
551
-     *
552
-     * @param string $name  variable name
553
-     * @param mixed  $value variable value
554
-     *
555
-     * @return  array
556
-     */
557
-    public function setQueryVariable($name, $value)
558
-    {
559
-        $array = $this->getQueryVariables();
560
-        $array[$name] = $value;
561
-        $this->setQueryVariables($array);
562
-    }
563
-
564
-    /**
565
-     * Removes the specifed variable from the query string.
566
-     *
567
-     * @param string $name a query string variable, e.g. "foo" in "?foo=1"
568
-     *
569
-     * @return void
570
-     */
571
-    public function unsetQueryVariable($name)
572
-    {
573
-        $array = $this->getQueryVariables();
574
-        unset($array[$name]);
575
-        $this->setQueryVariables($array);
576
-    }
577
-
578
-    /**
579
-     * Returns a string representation of this URL.
580
-     *
581
-     * @return  string
582
-     */
583
-    public function getURL()
584
-    {
585
-        // See RFC 3986, section 5.3
586
-        $url = "";
587
-
588
-        if ($this->_scheme !== false) {
589
-            $url .= $this->_scheme . ':';
590
-        }
591
-
592
-        $authority = $this->getAuthority();
593
-        if ($authority !== false) {
594
-            $url .= '//' . $authority;
595
-        }
596
-        $url .= $this->_path;
597
-
598
-        if ($this->_query !== false) {
599
-            $url .= '?' . $this->_query;
600
-        }
601
-
602
-        if ($this->_fragment !== false) {
603
-            $url .= '#' . $this->_fragment;
604
-        }
201
+	/**
202
+	 * Returns the scheme, e.g. "http" or "urn", or false if there is no
203
+	 * scheme specified, i.e. if this is a relative URL.
204
+	 *
205
+	 * @return  string|bool
206
+	 */
207
+	public function getScheme()
208
+	{
209
+		return $this->_scheme;
210
+	}
211
+
212
+	/**
213
+	 * Sets the scheme, e.g. "http" or "urn". Specify false if there is no
214
+	 * scheme specified, i.e. if this is a relative URL.
215
+	 *
216
+	 * @param string|bool $scheme e.g. "http" or "urn", or false if there is no
217
+	 *                            scheme specified, i.e. if this is a relative
218
+	 *                            URL
219
+	 *
220
+	 * @return void
221
+	 * @see    getScheme()
222
+	 */
223
+	public function setScheme($scheme)
224
+	{
225
+		$this->_scheme = $scheme;
226
+	}
227
+
228
+	/**
229
+	 * Returns the user part of the userinfo part (the part preceding the first
230
+	 *  ":"), or false if there is no userinfo part.
231
+	 *
232
+	 * @return  string|bool
233
+	 */
234
+	public function getUser()
235
+	{
236
+		return $this->_userinfo !== false
237
+			? preg_replace('@:.*$@', '', $this->_userinfo)
238
+			: false;
239
+	}
240
+
241
+	/**
242
+	 * Returns the password part of the userinfo part (the part after the first
243
+	 *  ":"), or false if there is no userinfo part (i.e. the URL does not
244
+	 * contain "@" in front of the hostname) or the userinfo part does not
245
+	 * contain ":".
246
+	 *
247
+	 * @return  string|bool
248
+	 */
249
+	public function getPassword()
250
+	{
251
+		return $this->_userinfo !== false
252
+			? substr(strstr($this->_userinfo, ':'), 1)
253
+			: false;
254
+	}
255
+
256
+	/**
257
+	 * Returns the userinfo part, or false if there is none, i.e. if the
258
+	 * authority part does not contain "@".
259
+	 *
260
+	 * @return  string|bool
261
+	 */
262
+	public function getUserinfo()
263
+	{
264
+		return $this->_userinfo;
265
+	}
266
+
267
+	/**
268
+	 * Sets the userinfo part. If two arguments are passed, they are combined
269
+	 * in the userinfo part as username ":" password.
270
+	 *
271
+	 * @param string|bool $userinfo userinfo or username
272
+	 * @param string|bool $password optional password, or false
273
+	 *
274
+	 * @return void
275
+	 */
276
+	public function setUserinfo($userinfo, $password = false)
277
+	{
278
+		$this->_userinfo = $userinfo;
279
+		if ($password !== false) {
280
+			$this->_userinfo .= ':' . $password;
281
+		}
282
+	}
283
+
284
+	/**
285
+	 * Returns the host part, or false if there is no authority part, e.g.
286
+	 * relative URLs.
287
+	 *
288
+	 * @return  string|bool a hostname, an IP address, or false
289
+	 */
290
+	public function getHost()
291
+	{
292
+		return $this->_host;
293
+	}
294
+
295
+	/**
296
+	 * Sets the host part. Specify false if there is no authority part, e.g.
297
+	 * relative URLs.
298
+	 *
299
+	 * @param string|bool $host a hostname, an IP address, or false
300
+	 *
301
+	 * @return void
302
+	 */
303
+	public function setHost($host)
304
+	{
305
+		$this->_host = $host;
306
+	}
307
+
308
+	/**
309
+	 * Returns the port number, or false if there is no port number specified,
310
+	 * i.e. if the default port is to be used.
311
+	 *
312
+	 * @return  string|bool
313
+	 */
314
+	public function getPort()
315
+	{
316
+		return $this->_port;
317
+	}
318
+
319
+	/**
320
+	 * Sets the port number. Specify false if there is no port number specified,
321
+	 * i.e. if the default port is to be used.
322
+	 *
323
+	 * @param string|bool $port a port number, or false
324
+	 *
325
+	 * @return void
326
+	 */
327
+	public function setPort($port)
328
+	{
329
+		$this->_port = $port;
330
+	}
331
+
332
+	/**
333
+	 * Returns the authority part, i.e. [ userinfo "@" ] host [ ":" port ], or
334
+	 * false if there is no authority.
335
+	 *
336
+	 * @return string|bool
337
+	 */
338
+	public function getAuthority()
339
+	{
340
+		if (!$this->_host) {
341
+			return false;
342
+		}
343
+
344
+		$authority = '';
345
+
346
+		if ($this->_userinfo !== false) {
347
+			$authority .= $this->_userinfo . '@';
348
+		}
349
+
350
+		$authority .= $this->_host;
351
+
352
+		if ($this->_port !== false) {
353
+			$authority .= ':' . $this->_port;
354
+		}
355
+
356
+		return $authority;
357
+	}
358
+
359
+	/**
360
+	 * Sets the authority part, i.e. [ userinfo "@" ] host [ ":" port ]. Specify
361
+	 * false if there is no authority.
362
+	 *
363
+	 * @param string|false $authority a hostname or an IP addresse, possibly
364
+	 *                                with userinfo prefixed and port number
365
+	 *                                appended, e.g. "foo:[email protected]:81".
366
+	 *
367
+	 * @return void
368
+	 */
369
+	public function setAuthority($authority)
370
+	{
371
+		$this->_userinfo = false;
372
+		$this->_host     = false;
373
+		$this->_port     = false;
374
+		if (preg_match('@^(([^\@]*)\@)?([^:]+)(:(\d*))?$@', $authority, $reg)) {
375
+			if ($reg[1]) {
376
+				$this->_userinfo = $reg[2];
377
+			}
378
+
379
+			$this->_host = $reg[3];
380
+			if (isset($reg[5])) {
381
+				$this->_port = $reg[5];
382
+			}
383
+		}
384
+	}
385
+
386
+	/**
387
+	 * Returns the path part (possibly an empty string).
388
+	 *
389
+	 * @return string
390
+	 */
391
+	public function getPath()
392
+	{
393
+		return $this->_path;
394
+	}
395
+
396
+	/**
397
+	 * Sets the path part (possibly an empty string).
398
+	 *
399
+	 * @param string $path a path
400
+	 *
401
+	 * @return void
402
+	 */
403
+	public function setPath($path)
404
+	{
405
+		$this->_path = $path;
406
+	}
407
+
408
+	/**
409
+	 * Returns the query string (excluding the leading "?"), or false if "?"
410
+	 * is not present in the URL.
411
+	 *
412
+	 * @return  string|bool
413
+	 * @see     self::getQueryVariables()
414
+	 */
415
+	public function getQuery()
416
+	{
417
+		return $this->_query;
418
+	}
419
+
420
+	/**
421
+	 * Sets the query string (excluding the leading "?"). Specify false if "?"
422
+	 * is not present in the URL.
423
+	 *
424
+	 * @param string|bool $query a query string, e.g. "foo=1&bar=2"
425
+	 *
426
+	 * @return void
427
+	 * @see   self::setQueryVariables()
428
+	 */
429
+	public function setQuery($query)
430
+	{
431
+		$this->_query = $query;
432
+	}
433
+
434
+	/**
435
+	 * Returns the fragment name, or false if "#" is not present in the URL.
436
+	 *
437
+	 * @return  string|bool
438
+	 */
439
+	public function getFragment()
440
+	{
441
+		return $this->_fragment;
442
+	}
443
+
444
+	/**
445
+	 * Sets the fragment name. Specify false if "#" is not present in the URL.
446
+	 *
447
+	 * @param string|bool $fragment a fragment excluding the leading "#", or
448
+	 *                              false
449
+	 *
450
+	 * @return void
451
+	 */
452
+	public function setFragment($fragment)
453
+	{
454
+		$this->_fragment = $fragment;
455
+	}
456
+
457
+	/**
458
+	 * Returns the query string like an array as the variables would appear in
459
+	 * $_GET in a PHP script. If the URL does not contain a "?", an empty array
460
+	 * is returned.
461
+	 *
462
+	 * @return  array
463
+	 */
464
+	public function getQueryVariables()
465
+	{
466
+		$pattern = '/[' .
467
+				   preg_quote($this->getOption(self::OPTION_SEPARATOR_INPUT), '/') .
468
+				   ']/';
469
+		$parts   = preg_split($pattern, $this->_query, -1, PREG_SPLIT_NO_EMPTY);
470
+		$return  = array();
471
+
472
+		foreach ($parts as $part) {
473
+			if (strpos($part, '=') !== false) {
474
+				list($key, $value) = explode('=', $part, 2);
475
+			} else {
476
+				$key   = $part;
477
+				$value = null;
478
+			}
479
+
480
+			if ($this->getOption(self::OPTION_ENCODE_KEYS)) {
481
+				$key = rawurldecode($key);
482
+			}
483
+			$value = rawurldecode($value);
484
+
485
+			if ($this->getOption(self::OPTION_USE_BRACKETS) &&
486
+				preg_match('#^(.*)\[([0-9a-z_-]*)\]#i', $key, $matches)) {
487
+
488
+				$key = $matches[1];
489
+				$idx = $matches[2];
490
+
491
+				// Ensure is an array
492
+				if (empty($return[$key]) || !is_array($return[$key])) {
493
+					$return[$key] = array();
494
+				}
495
+
496
+				// Add data
497
+				if ($idx === '') {
498
+					$return[$key][] = $value;
499
+				} else {
500
+					$return[$key][$idx] = $value;
501
+				}
502
+			} elseif (!$this->getOption(self::OPTION_USE_BRACKETS)
503
+					  && !empty($return[$key])
504
+			) {
505
+				$return[$key]   = (array) $return[$key];
506
+				$return[$key][] = $value;
507
+			} else {
508
+				$return[$key] = $value;
509
+			}
510
+		}
511
+
512
+		return $return;
513
+	}
514
+
515
+	/**
516
+	 * Sets the query string to the specified variable in the query string.
517
+	 *
518
+	 * @param array $array (name => value) array
519
+	 *
520
+	 * @return void
521
+	 */
522
+	public function setQueryVariables(array $array)
523
+	{
524
+		if (!$array) {
525
+			$this->_query = false;
526
+		} else {
527
+			foreach ($array as $name => $value) {
528
+				if ($this->getOption(self::OPTION_ENCODE_KEYS)) {
529
+					$name = self::urlencode($name);
530
+				}
531
+
532
+				if (is_array($value)) {
533
+					foreach ($value as $k => $v) {
534
+						$parts[] = $this->getOption(self::OPTION_USE_BRACKETS)
535
+							? sprintf('%s[%s]=%s', $name, $k, $v)
536
+							: ($name . '=' . $v);
537
+					}
538
+				} elseif (!is_null($value)) {
539
+					$parts[] = $name . '=' . self::urlencode($value);
540
+				} else {
541
+					$parts[] = $name;
542
+				}
543
+			}
544
+			$this->_query = implode($this->getOption(self::OPTION_SEPARATOR_OUTPUT),
545
+									$parts);
546
+		}
547
+	}
548
+
549
+	/**
550
+	 * Sets the specified variable in the query string.
551
+	 *
552
+	 * @param string $name  variable name
553
+	 * @param mixed  $value variable value
554
+	 *
555
+	 * @return  array
556
+	 */
557
+	public function setQueryVariable($name, $value)
558
+	{
559
+		$array = $this->getQueryVariables();
560
+		$array[$name] = $value;
561
+		$this->setQueryVariables($array);
562
+	}
563
+
564
+	/**
565
+	 * Removes the specifed variable from the query string.
566
+	 *
567
+	 * @param string $name a query string variable, e.g. "foo" in "?foo=1"
568
+	 *
569
+	 * @return void
570
+	 */
571
+	public function unsetQueryVariable($name)
572
+	{
573
+		$array = $this->getQueryVariables();
574
+		unset($array[$name]);
575
+		$this->setQueryVariables($array);
576
+	}
577
+
578
+	/**
579
+	 * Returns a string representation of this URL.
580
+	 *
581
+	 * @return  string
582
+	 */
583
+	public function getURL()
584
+	{
585
+		// See RFC 3986, section 5.3
586
+		$url = "";
587
+
588
+		if ($this->_scheme !== false) {
589
+			$url .= $this->_scheme . ':';
590
+		}
591
+
592
+		$authority = $this->getAuthority();
593
+		if ($authority !== false) {
594
+			$url .= '//' . $authority;
595
+		}
596
+		$url .= $this->_path;
597
+
598
+		if ($this->_query !== false) {
599
+			$url .= '?' . $this->_query;
600
+		}
601
+
602
+		if ($this->_fragment !== false) {
603
+			$url .= '#' . $this->_fragment;
604
+		}
605 605
     
606
-        return $url;
607
-    }
608
-
609
-    /**
610
-     * Returns a string representation of this URL.
611
-     *
612
-     * @return  string
613
-     * @see toString()
614
-     */
615
-    public function __toString()
616
-    {
617
-        return $this->getURL();
618
-    }
619
-
620
-    /** 
621
-     * Returns a normalized string representation of this URL. This is useful
622
-     * for comparison of URLs.
623
-     *
624
-     * @return  string
625
-     */
626
-    public function getNormalizedURL()
627
-    {
628
-        $url = clone $this;
629
-        $url->normalize();
630
-        return $url->getUrl();
631
-    }
632
-
633
-    /** 
634
-     * Returns a normalized Net_URL2 instance.
635
-     *
636
-     * @return  Net_URL2
637
-     */
638
-    public function normalize()
639
-    {
640
-        // See RFC 3886, section 6
641
-
642
-        // Schemes are case-insensitive
643
-        if ($this->_scheme) {
644
-            $this->_scheme = strtolower($this->_scheme);
645
-        }
646
-
647
-        // Hostnames are case-insensitive
648
-        if ($this->_host) {
649
-            $this->_host = strtolower($this->_host);
650
-        }
651
-
652
-        // Remove default port number for known schemes (RFC 3986, section 6.2.3)
653
-        if ($this->_port &&
654
-            $this->_scheme &&
655
-            $this->_port == getservbyname($this->_scheme, 'tcp')) {
656
-
657
-            $this->_port = false;
658
-        }
659
-
660
-        // Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1)
661
-        foreach (array('_userinfo', '_host', '_path') as $part) {
662
-            if ($this->$part) {
663
-                $this->$part = preg_replace('/%[0-9a-f]{2}/ie',
664
-                                            'strtoupper("\0")',
665
-                                            $this->$part);
666
-            }
667
-        }
668
-
669
-        // Path segment normalization (RFC 3986, section 6.2.2.3)
670
-        $this->_path = self::removeDotSegments($this->_path);
671
-
672
-        // Scheme based normalization (RFC 3986, section 6.2.3)
673
-        if ($this->_host && !$this->_path) {
674
-            $this->_path = '/';
675
-        }
676
-    }
677
-
678
-    /**
679
-     * Returns whether this instance represents an absolute URL.
680
-     *
681
-     * @return  bool
682
-     */
683
-    public function isAbsolute()
684
-    {
685
-        return (bool) $this->_scheme;
686
-    }
687
-
688
-    /**
689
-     * Returns an Net_URL2 instance representing an absolute URL relative to
690
-     * this URL.
691
-     *
692
-     * @param Net_URL2|string $reference relative URL
693
-     *
694
-     * @return Net_URL2
695
-     */
696
-    public function resolve($reference)
697
-    {
698
-        if (!$reference instanceof Net_URL2) {
699
-            $reference = new self($reference);
700
-        }
701
-        if (!$this->isAbsolute()) {
702
-            throw new Exception('Base-URL must be absolute');
703
-        }
704
-
705
-        // A non-strict parser may ignore a scheme in the reference if it is
706
-        // identical to the base URI's scheme.
707
-        if (!$this->getOption(self::OPTION_STRICT) && $reference->_scheme == $this->_scheme) {
708
-            $reference->_scheme = false;
709
-        }
710
-
711
-        $target = new self('');
712
-        if ($reference->_scheme !== false) {
713
-            $target->_scheme = $reference->_scheme;
714
-            $target->setAuthority($reference->getAuthority());
715
-            $target->_path  = self::removeDotSegments($reference->_path);
716
-            $target->_query = $reference->_query;
717
-        } else {
718
-            $authority = $reference->getAuthority();
719
-            if ($authority !== false) {
720
-                $target->setAuthority($authority);
721
-                $target->_path  = self::removeDotSegments($reference->_path);
722
-                $target->_query = $reference->_query;
723
-            } else {
724
-                if ($reference->_path == '') {
725
-                    $target->_path = $this->_path;
726
-                    if ($reference->_query !== false) {
727
-                        $target->_query = $reference->_query;
728
-                    } else {
729
-                        $target->_query = $this->_query;
730
-                    }
731
-                } else {
732
-                    if (substr($reference->_path, 0, 1) == '/') {
733
-                        $target->_path = self::removeDotSegments($reference->_path);
734
-                    } else {
735
-                        // Merge paths (RFC 3986, section 5.2.3)
736
-                        if ($this->_host !== false && $this->_path == '') {
737
-                            $target->_path = '/' . $this->_path;
738
-                        } else {
739
-                            $i = strrpos($this->_path, '/');
740
-                            if ($i !== false) {
741
-                                $target->_path = substr($this->_path, 0, $i + 1);
742
-                            }
743
-                            $target->_path .= $reference->_path;
744
-                        }
745
-                        $target->_path = self::removeDotSegments($target->_path);
746
-                    }
747
-                    $target->_query = $reference->_query;
748
-                }
749
-                $target->setAuthority($this->getAuthority());
750
-            }
751
-            $target->_scheme = $this->_scheme;
752
-        }
753
-
754
-        $target->_fragment = $reference->_fragment;
755
-
756
-        return $target;
757
-    }
758
-
759
-    /**
760
-     * Removes dots as described in RFC 3986, section 5.2.4, e.g.
761
-     * "/foo/../bar/baz" => "/bar/baz"
762
-     *
763
-     * @param string $path a path
764
-     *
765
-     * @return string a path
766
-     */
767
-    public static function removeDotSegments($path)
768
-    {
769
-        $output = '';
770
-
771
-        // Make sure not to be trapped in an infinite loop due to a bug in this
772
-        // method
773
-        $j = 0; 
774
-        while ($path && $j++ < 100) {
775
-            if (substr($path, 0, 2) == './') {
776
-                // Step 2.A
777
-                $path = substr($path, 2);
778
-            } elseif (substr($path, 0, 3) == '../') {
779
-                // Step 2.A
780
-                $path = substr($path, 3);
781
-            } elseif (substr($path, 0, 3) == '/./' || $path == '/.') {
782
-                // Step 2.B
783
-                $path = '/' . substr($path, 3);
784
-            } elseif (substr($path, 0, 4) == '/../' || $path == '/..') {
785
-                // Step 2.C
786
-                $path   = '/' . substr($path, 4);
787
-                $i      = strrpos($output, '/');
788
-                $output = $i === false ? '' : substr($output, 0, $i);
789
-            } elseif ($path == '.' || $path == '..') {
790
-                // Step 2.D
791
-                $path = '';
792
-            } else {
793
-                // Step 2.E
794
-                $i = strpos($path, '/');
795
-                if ($i === 0) {
796
-                    $i = strpos($path, '/', 1);
797
-                }
798
-                if ($i === false) {
799
-                    $i = strlen($path);
800
-                }
801
-                $output .= substr($path, 0, $i);
802
-                $path = substr($path, $i);
803
-            }
804
-        }
805
-
806
-        return $output;
807
-    }
808
-
809
-    /**
810
-     * Percent-encodes all non-alphanumeric characters except these: _ . - ~
811
-     * Similar to PHP's rawurlencode(), except that it also encodes ~ in PHP
812
-     * 5.2.x and earlier.
813
-     *
814
-     * @param  $raw the string to encode
815
-     * @return string
816
-     */
817
-    public static function urlencode($string)
818
-    {
819
-    	$encoded = rawurlencode($string);
606
+		return $url;
607
+	}
608
+
609
+	/**
610
+	 * Returns a string representation of this URL.
611
+	 *
612
+	 * @return  string
613
+	 * @see toString()
614
+	 */
615
+	public function __toString()
616
+	{
617
+		return $this->getURL();
618
+	}
619
+
620
+	/** 
621
+	 * Returns a normalized string representation of this URL. This is useful
622
+	 * for comparison of URLs.
623
+	 *
624
+	 * @return  string
625
+	 */
626
+	public function getNormalizedURL()
627
+	{
628
+		$url = clone $this;
629
+		$url->normalize();
630
+		return $url->getUrl();
631
+	}
632
+
633
+	/** 
634
+	 * Returns a normalized Net_URL2 instance.
635
+	 *
636
+	 * @return  Net_URL2
637
+	 */
638
+	public function normalize()
639
+	{
640
+		// See RFC 3886, section 6
641
+
642
+		// Schemes are case-insensitive
643
+		if ($this->_scheme) {
644
+			$this->_scheme = strtolower($this->_scheme);
645
+		}
646
+
647
+		// Hostnames are case-insensitive
648
+		if ($this->_host) {
649
+			$this->_host = strtolower($this->_host);
650
+		}
651
+
652
+		// Remove default port number for known schemes (RFC 3986, section 6.2.3)
653
+		if ($this->_port &&
654
+			$this->_scheme &&
655
+			$this->_port == getservbyname($this->_scheme, 'tcp')) {
656
+
657
+			$this->_port = false;
658
+		}
659
+
660
+		// Normalize case of %XX percentage-encodings (RFC 3986, section 6.2.2.1)
661
+		foreach (array('_userinfo', '_host', '_path') as $part) {
662
+			if ($this->$part) {
663
+				$this->$part = preg_replace('/%[0-9a-f]{2}/ie',
664
+											'strtoupper("\0")',
665
+											$this->$part);
666
+			}
667
+		}
668
+
669
+		// Path segment normalization (RFC 3986, section 6.2.2.3)
670
+		$this->_path = self::removeDotSegments($this->_path);
671
+
672
+		// Scheme based normalization (RFC 3986, section 6.2.3)
673
+		if ($this->_host && !$this->_path) {
674
+			$this->_path = '/';
675
+		}
676
+	}
677
+
678
+	/**
679
+	 * Returns whether this instance represents an absolute URL.
680
+	 *
681
+	 * @return  bool
682
+	 */
683
+	public function isAbsolute()
684
+	{
685
+		return (bool) $this->_scheme;
686
+	}
687
+
688
+	/**
689
+	 * Returns an Net_URL2 instance representing an absolute URL relative to
690
+	 * this URL.
691
+	 *
692
+	 * @param Net_URL2|string $reference relative URL
693
+	 *
694
+	 * @return Net_URL2
695
+	 */
696
+	public function resolve($reference)
697
+	{
698
+		if (!$reference instanceof Net_URL2) {
699
+			$reference = new self($reference);
700
+		}
701
+		if (!$this->isAbsolute()) {
702
+			throw new Exception('Base-URL must be absolute');
703
+		}
704
+
705
+		// A non-strict parser may ignore a scheme in the reference if it is
706
+		// identical to the base URI's scheme.
707
+		if (!$this->getOption(self::OPTION_STRICT) && $reference->_scheme == $this->_scheme) {
708
+			$reference->_scheme = false;
709
+		}
710
+
711
+		$target = new self('');
712
+		if ($reference->_scheme !== false) {
713
+			$target->_scheme = $reference->_scheme;
714
+			$target->setAuthority($reference->getAuthority());
715
+			$target->_path  = self::removeDotSegments($reference->_path);
716
+			$target->_query = $reference->_query;
717
+		} else {
718
+			$authority = $reference->getAuthority();
719
+			if ($authority !== false) {
720
+				$target->setAuthority($authority);
721
+				$target->_path  = self::removeDotSegments($reference->_path);
722
+				$target->_query = $reference->_query;
723
+			} else {
724
+				if ($reference->_path == '') {
725
+					$target->_path = $this->_path;
726
+					if ($reference->_query !== false) {
727
+						$target->_query = $reference->_query;
728
+					} else {
729
+						$target->_query = $this->_query;
730
+					}
731
+				} else {
732
+					if (substr($reference->_path, 0, 1) == '/') {
733
+						$target->_path = self::removeDotSegments($reference->_path);
734
+					} else {
735
+						// Merge paths (RFC 3986, section 5.2.3)
736
+						if ($this->_host !== false && $this->_path == '') {
737
+							$target->_path = '/' . $this->_path;
738
+						} else {
739
+							$i = strrpos($this->_path, '/');
740
+							if ($i !== false) {
741
+								$target->_path = substr($this->_path, 0, $i + 1);
742
+							}
743
+							$target->_path .= $reference->_path;
744
+						}
745
+						$target->_path = self::removeDotSegments($target->_path);
746
+					}
747
+					$target->_query = $reference->_query;
748
+				}
749
+				$target->setAuthority($this->getAuthority());
750
+			}
751
+			$target->_scheme = $this->_scheme;
752
+		}
753
+
754
+		$target->_fragment = $reference->_fragment;
755
+
756
+		return $target;
757
+	}
758
+
759
+	/**
760
+	 * Removes dots as described in RFC 3986, section 5.2.4, e.g.
761
+	 * "/foo/../bar/baz" => "/bar/baz"
762
+	 *
763
+	 * @param string $path a path
764
+	 *
765
+	 * @return string a path
766
+	 */
767
+	public static function removeDotSegments($path)
768
+	{
769
+		$output = '';
770
+
771
+		// Make sure not to be trapped in an infinite loop due to a bug in this
772
+		// method
773
+		$j = 0; 
774
+		while ($path && $j++ < 100) {
775
+			if (substr($path, 0, 2) == './') {
776
+				// Step 2.A
777
+				$path = substr($path, 2);
778
+			} elseif (substr($path, 0, 3) == '../') {
779
+				// Step 2.A
780
+				$path = substr($path, 3);
781
+			} elseif (substr($path, 0, 3) == '/./' || $path == '/.') {
782
+				// Step 2.B
783
+				$path = '/' . substr($path, 3);
784
+			} elseif (substr($path, 0, 4) == '/../' || $path == '/..') {
785
+				// Step 2.C
786
+				$path   = '/' . substr($path, 4);
787
+				$i      = strrpos($output, '/');
788
+				$output = $i === false ? '' : substr($output, 0, $i);
789
+			} elseif ($path == '.' || $path == '..') {
790
+				// Step 2.D
791
+				$path = '';
792
+			} else {
793
+				// Step 2.E
794
+				$i = strpos($path, '/');
795
+				if ($i === 0) {
796
+					$i = strpos($path, '/', 1);
797
+				}
798
+				if ($i === false) {
799
+					$i = strlen($path);
800
+				}
801
+				$output .= substr($path, 0, $i);
802
+				$path = substr($path, $i);
803
+			}
804
+		}
805
+
806
+		return $output;
807
+	}
808
+
809
+	/**
810
+	 * Percent-encodes all non-alphanumeric characters except these: _ . - ~
811
+	 * Similar to PHP's rawurlencode(), except that it also encodes ~ in PHP
812
+	 * 5.2.x and earlier.
813
+	 *
814
+	 * @param  $raw the string to encode
815
+	 * @return string
816
+	 */
817
+	public static function urlencode($string)
818
+	{
819
+		$encoded = rawurlencode($string);
820 820
 	// This is only necessary in PHP < 5.3.
821 821
 	$encoded = str_replace('%7E', '~', $encoded);
822 822
 	return $encoded;
823
-    }
824
-
825
-    /**
826
-     * Returns a Net_URL2 instance representing the canonical URL of the
827
-     * currently executing PHP script.
828
-     * 
829
-     * @return  string
830
-     */
831
-    public static function getCanonical()
832
-    {
833
-        if (!isset($_SERVER['REQUEST_METHOD'])) {
834
-            // ALERT - no current URL
835
-            throw new Exception('Script was not called through a webserver');
836
-        }
837
-
838
-        // Begin with a relative URL
839
-        $url = new self($_SERVER['PHP_SELF']);
840
-        $url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
841
-        $url->_host   = $_SERVER['SERVER_NAME'];
842
-        $port = $_SERVER['SERVER_PORT'];
843
-        if ($url->_scheme == 'http' && $port != 80 ||
844
-            $url->_scheme == 'https' && $port != 443) {
845
-
846
-            $url->_port = $port;
847
-        }
848
-        return $url;
849
-    }
850
-
851
-    /**
852
-     * Returns the URL used to retrieve the current request.
853
-     *
854
-     * @return  string
855
-     */
856
-    public static function getRequestedURL()
857
-    {
858
-        return self::getRequested()->getUrl();
859
-    }
860
-
861
-    /**
862
-     * Returns a Net_URL2 instance representing the URL used to retrieve the
863
-     * current request.
864
-     *
865
-     * @return  Net_URL2
866
-     */
867
-    public static function getRequested()
868
-    {
869
-        if (!isset($_SERVER['REQUEST_METHOD'])) {
870
-            // ALERT - no current URL
871
-            throw new Exception('Script was not called through a webserver');
872
-        }
873
-
874
-        // Begin with a relative URL
875
-        $url = new self($_SERVER['REQUEST_URI']);
876
-        $url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
877
-        // Set host and possibly port
878
-        $url->setAuthority($_SERVER['HTTP_HOST']);
879
-        return $url;
880
-    }
881
-
882
-    /**
883
-     * Returns the value of the specified option.
884
-     *
885
-     * @param string $optionName The name of the option to retrieve
886
-     *
887
-     * @return  mixed
888
-     */
889
-    function getOption($optionName)
890
-    {
891
-        return isset($this->_options[$optionName])
892
-            ? $this->_options[$optionName] : false;
893
-    }
823
+	}
824
+
825
+	/**
826
+	 * Returns a Net_URL2 instance representing the canonical URL of the
827
+	 * currently executing PHP script.
828
+	 * 
829
+	 * @return  string
830
+	 */
831
+	public static function getCanonical()
832
+	{
833
+		if (!isset($_SERVER['REQUEST_METHOD'])) {
834
+			// ALERT - no current URL
835
+			throw new Exception('Script was not called through a webserver');
836
+		}
837
+
838
+		// Begin with a relative URL
839
+		$url = new self($_SERVER['PHP_SELF']);
840
+		$url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
841
+		$url->_host   = $_SERVER['SERVER_NAME'];
842
+		$port = $_SERVER['SERVER_PORT'];
843
+		if ($url->_scheme == 'http' && $port != 80 ||
844
+			$url->_scheme == 'https' && $port != 443) {
845
+
846
+			$url->_port = $port;
847
+		}
848
+		return $url;
849
+	}
850
+
851
+	/**
852
+	 * Returns the URL used to retrieve the current request.
853
+	 *
854
+	 * @return  string
855
+	 */
856
+	public static function getRequestedURL()
857
+	{
858
+		return self::getRequested()->getUrl();
859
+	}
860
+
861
+	/**
862
+	 * Returns a Net_URL2 instance representing the URL used to retrieve the
863
+	 * current request.
864
+	 *
865
+	 * @return  Net_URL2
866
+	 */
867
+	public static function getRequested()
868
+	{
869
+		if (!isset($_SERVER['REQUEST_METHOD'])) {
870
+			// ALERT - no current URL
871
+			throw new Exception('Script was not called through a webserver');
872
+		}
873
+
874
+		// Begin with a relative URL
875
+		$url = new self($_SERVER['REQUEST_URI']);
876
+		$url->_scheme = isset($_SERVER['HTTPS']) ? 'https' : 'http';
877
+		// Set host and possibly port
878
+		$url->setAuthority($_SERVER['HTTP_HOST']);
879
+		return $url;
880
+	}
881
+
882
+	/**
883
+	 * Returns the value of the specified option.
884
+	 *
885
+	 * @param string $optionName The name of the option to retrieve
886
+	 *
887
+	 * @return  mixed
888
+	 */
889
+	function getOption($optionName)
890
+	{
891
+		return isset($this->_options[$optionName])
892
+			? $this->_options[$optionName] : false;
893
+	}
894 894
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      */
172 172
     public function __set($var, $arg)
173 173
     {
174
-        $method = 'set' . $var;
174
+        $method = 'set'.$var;
175 175
         if (method_exists($this, $method)) {
176 176
             $this->$method($arg);
177 177
         }
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
      */
191 191
     public function __get($var)
192 192
     {
193
-        $method = 'get' . $var;
193
+        $method = 'get'.$var;
194 194
         if (method_exists($this, $method)) {
195 195
             return $this->$method();
196 196
         }
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
     {
278 278
         $this->_userinfo = $userinfo;
279 279
         if ($password !== false) {
280
-            $this->_userinfo .= ':' . $password;
280
+            $this->_userinfo .= ':'.$password;
281 281
         }
282 282
     }
283 283
 
@@ -344,13 +344,13 @@  discard block
 block discarded – undo
344 344
         $authority = '';
345 345
 
346 346
         if ($this->_userinfo !== false) {
347
-            $authority .= $this->_userinfo . '@';
347
+            $authority .= $this->_userinfo.'@';
348 348
         }
349 349
 
350 350
         $authority .= $this->_host;
351 351
 
352 352
         if ($this->_port !== false) {
353
-            $authority .= ':' . $this->_port;
353
+            $authority .= ':'.$this->_port;
354 354
         }
355 355
 
356 356
         return $authority;
@@ -463,8 +463,8 @@  discard block
 block discarded – undo
463 463
      */
464 464
     public function getQueryVariables()
465 465
     {
466
-        $pattern = '/[' .
467
-                   preg_quote($this->getOption(self::OPTION_SEPARATOR_INPUT), '/') .
466
+        $pattern = '/['.
467
+                   preg_quote($this->getOption(self::OPTION_SEPARATOR_INPUT), '/').
468 468
                    ']/';
469 469
         $parts   = preg_split($pattern, $this->_query, -1, PREG_SPLIT_NO_EMPTY);
470 470
         $return  = array();
@@ -533,10 +533,10 @@  discard block
 block discarded – undo
533 533
                     foreach ($value as $k => $v) {
534 534
                         $parts[] = $this->getOption(self::OPTION_USE_BRACKETS)
535 535
                             ? sprintf('%s[%s]=%s', $name, $k, $v)
536
-                            : ($name . '=' . $v);
536
+                            : ($name.'='.$v);
537 537
                     }
538 538
                 } elseif (!is_null($value)) {
539
-                    $parts[] = $name . '=' . self::urlencode($value);
539
+                    $parts[] = $name.'='.self::urlencode($value);
540 540
                 } else {
541 541
                     $parts[] = $name;
542 542
                 }
@@ -586,21 +586,21 @@  discard block
 block discarded – undo
586 586
         $url = "";
587 587
 
588 588
         if ($this->_scheme !== false) {
589
-            $url .= $this->_scheme . ':';
589
+            $url .= $this->_scheme.':';
590 590
         }
591 591
 
592 592
         $authority = $this->getAuthority();
593 593
         if ($authority !== false) {
594
-            $url .= '//' . $authority;
594
+            $url .= '//'.$authority;
595 595
         }
596 596
         $url .= $this->_path;
597 597
 
598 598
         if ($this->_query !== false) {
599
-            $url .= '?' . $this->_query;
599
+            $url .= '?'.$this->_query;
600 600
         }
601 601
 
602 602
         if ($this->_fragment !== false) {
603
-            $url .= '#' . $this->_fragment;
603
+            $url .= '#'.$this->_fragment;
604 604
         }
605 605
     
606 606
         return $url;
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
                     } else {
735 735
                         // Merge paths (RFC 3986, section 5.2.3)
736 736
                         if ($this->_host !== false && $this->_path == '') {
737
-                            $target->_path = '/' . $this->_path;
737
+                            $target->_path = '/'.$this->_path;
738 738
                         } else {
739 739
                             $i = strrpos($this->_path, '/');
740 740
                             if ($i !== false) {
@@ -780,10 +780,10 @@  discard block
 block discarded – undo
780 780
                 $path = substr($path, 3);
781 781
             } elseif (substr($path, 0, 3) == '/./' || $path == '/.') {
782 782
                 // Step 2.B
783
-                $path = '/' . substr($path, 3);
783
+                $path = '/'.substr($path, 3);
784 784
             } elseif (substr($path, 0, 4) == '/../' || $path == '/..') {
785 785
                 // Step 2.C
786
-                $path   = '/' . substr($path, 4);
786
+                $path   = '/'.substr($path, 4);
787 787
                 $i      = strrpos($output, '/');
788 788
                 $output = $i === false ? '' : substr($output, 0, $i);
789 789
             } elseif ($path == '.' || $path == '..') {
Please login to merge, or discard this patch.
libs/PEAR/HTTP/Request.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -1267,6 +1267,7 @@  discard block
 block discarded – undo
1267 1267
     *
1268 1268
     * @access private
1269 1269
     * @param  string    value of Set-Cookie header
1270
+    * @param string $headervalue
1270 1271
     */
1271 1272
     function _parseCookie($headervalue)
1272 1273
     {
@@ -1349,6 +1350,7 @@  discard block
 block discarded – undo
1349 1350
     * 
1350 1351
     * @param    string  Event name
1351 1352
     * @param    mixed   Additional data
1353
+    * @param string $event
1352 1354
     * @access   private
1353 1355
     * @see HTTP_Request::_notify()
1354 1356
     */
@@ -1369,6 +1371,7 @@  discard block
 block discarded – undo
1369 1371
     *
1370 1372
     * @access   private
1371 1373
     * @param    string  gzip-encoded data
1374
+    * @param string $data
1372 1375
     * @return   string  decoded data
1373 1376
     */
1374 1377
     function _decodeGzip($data)
Please login to merge, or discard this patch.
Indentation   +1104 added lines, -1104 removed lines patch added patch discarded remove patch
@@ -80,12 +80,12 @@  discard block
 block discarded – undo
80 80
    /**
81 81
     * Whether string functions are overloaded by their mbstring equivalents 
82 82
     */
83
-    define('HTTP_REQUEST_MBSTRING', true);
83
+	define('HTTP_REQUEST_MBSTRING', true);
84 84
 } else {
85 85
    /**
86 86
     * @ignore
87 87
     */
88
-    define('HTTP_REQUEST_MBSTRING', false);
88
+	define('HTTP_REQUEST_MBSTRING', false);
89 89
 }
90 90
 
91 91
 /**
@@ -109,297 +109,297 @@  discard block
 block discarded – undo
109 109
    /**#@+
110 110
     * @access private
111 111
     */
112
-    /**
113
-    * Instance of Net_URL
114
-    * @var Net_URL
115
-    */
116
-    var $_url;
117
-
118
-    /**
119
-    * Type of request
120
-    * @var string
121
-    */
122
-    var $_method;
123
-
124
-    /**
125
-    * HTTP Version
126
-    * @var string
127
-    */
128
-    var $_http;
129
-
130
-    /**
131
-    * Request headers
132
-    * @var array
133
-    */
134
-    var $_requestHeaders;
135
-
136
-    /**
137
-    * Basic Auth Username
138
-    * @var string
139
-    */
140
-    var $_user;
112
+	/**
113
+	 * Instance of Net_URL
114
+	 * @var Net_URL
115
+	 */
116
+	var $_url;
117
+
118
+	/**
119
+	 * Type of request
120
+	 * @var string
121
+	 */
122
+	var $_method;
123
+
124
+	/**
125
+	 * HTTP Version
126
+	 * @var string
127
+	 */
128
+	var $_http;
129
+
130
+	/**
131
+	 * Request headers
132
+	 * @var array
133
+	 */
134
+	var $_requestHeaders;
135
+
136
+	/**
137
+	 * Basic Auth Username
138
+	 * @var string
139
+	 */
140
+	var $_user;
141 141
     
142
-    /**
143
-    * Basic Auth Password
144
-    * @var string
145
-    */
146
-    var $_pass;
147
-
148
-    /**
149
-    * Socket object
150
-    * @var Net_Socket
151
-    */
152
-    var $_sock;
142
+	/**
143
+	 * Basic Auth Password
144
+	 * @var string
145
+	 */
146
+	var $_pass;
147
+
148
+	/**
149
+	 * Socket object
150
+	 * @var Net_Socket
151
+	 */
152
+	var $_sock;
153 153
     
154
-    /**
155
-    * Proxy server
156
-    * @var string
157
-    */
158
-    var $_proxy_host;
154
+	/**
155
+	 * Proxy server
156
+	 * @var string
157
+	 */
158
+	var $_proxy_host;
159 159
     
160
-    /**
161
-    * Proxy port
162
-    * @var integer
163
-    */
164
-    var $_proxy_port;
160
+	/**
161
+	 * Proxy port
162
+	 * @var integer
163
+	 */
164
+	var $_proxy_port;
165 165
     
166
-    /**
167
-    * Proxy username
168
-    * @var string
169
-    */
170
-    var $_proxy_user;
166
+	/**
167
+	 * Proxy username
168
+	 * @var string
169
+	 */
170
+	var $_proxy_user;
171 171
     
172
-    /**
173
-    * Proxy password
174
-    * @var string
175
-    */
176
-    var $_proxy_pass;
177
-
178
-    /**
179
-    * Post data
180
-    * @var array
181
-    */
182
-    var $_postData;
172
+	/**
173
+	 * Proxy password
174
+	 * @var string
175
+	 */
176
+	var $_proxy_pass;
177
+
178
+	/**
179
+	 * Post data
180
+	 * @var array
181
+	 */
182
+	var $_postData;
183 183
 
184 184
    /**
185 185
     * Request body  
186 186
     * @var string
187 187
     */
188
-    var $_body;
188
+	var $_body;
189 189
 
190 190
    /**
191 191
     * A list of methods that MUST NOT have a request body, per RFC 2616
192 192
     * @var array
193 193
     */
194
-    var $_bodyDisallowed = array('TRACE');
194
+	var $_bodyDisallowed = array('TRACE');
195 195
 
196 196
    /**
197 197
     * Files to post 
198 198
     * @var array
199 199
     */
200
-    var $_postFiles = array();
200
+	var $_postFiles = array();
201 201
 
202
-    /**
203
-    * Connection timeout.
204
-    * @var float
205
-    */
206
-    var $_timeout;
202
+	/**
203
+	 * Connection timeout.
204
+	 * @var float
205
+	 */
206
+	var $_timeout;
207 207
     
208
-    /**
209
-    * HTTP_Response object
210
-    * @var HTTP_Response
211
-    */
212
-    var $_response;
208
+	/**
209
+	 * HTTP_Response object
210
+	 * @var HTTP_Response
211
+	 */
212
+	var $_response;
213 213
     
214
-    /**
215
-    * Whether to allow redirects
216
-    * @var boolean
217
-    */
218
-    var $_allowRedirects;
214
+	/**
215
+	 * Whether to allow redirects
216
+	 * @var boolean
217
+	 */
218
+	var $_allowRedirects;
219 219
     
220
-    /**
221
-    * Maximum redirects allowed
222
-    * @var integer
223
-    */
224
-    var $_maxRedirects;
220
+	/**
221
+	 * Maximum redirects allowed
222
+	 * @var integer
223
+	 */
224
+	var $_maxRedirects;
225 225
     
226
-    /**
227
-    * Current number of redirects
228
-    * @var integer
229
-    */
230
-    var $_redirects;
226
+	/**
227
+	 * Current number of redirects
228
+	 * @var integer
229
+	 */
230
+	var $_redirects;
231 231
 
232 232
    /**
233 233
     * Whether to append brackets [] to array variables
234 234
     * @var bool
235 235
     */
236
-    var $_useBrackets = true;
236
+	var $_useBrackets = true;
237 237
 
238 238
    /**
239 239
     * Attached listeners
240 240
     * @var array
241 241
     */
242
-    var $_listeners = array();
242
+	var $_listeners = array();
243 243
 
244 244
    /**
245 245
     * Whether to save response body in response object property  
246 246
     * @var bool
247 247
     */
248
-    var $_saveBody = true;
248
+	var $_saveBody = true;
249 249
 
250 250
    /**
251 251
     * Timeout for reading from socket (array(seconds, microseconds))
252 252
     * @var array
253 253
     */
254
-    var $_readTimeout = null;
254
+	var $_readTimeout = null;
255 255
 
256 256
    /**
257 257
     * Options to pass to Net_Socket::connect. See stream_context_create
258 258
     * @var array
259 259
     */
260
-    var $_socketOptions = null;
260
+	var $_socketOptions = null;
261 261
    /**#@-*/
262 262
 
263
-    /**
264
-    * Constructor
265
-    *
266
-    * Sets up the object
267
-    * @param    string  The url to fetch/access
268
-    * @param    array   Associative array of parameters which can have the following keys:
269
-    * <ul>
270
-    *   <li>method         - Method to use, GET, POST etc (string)</li>
271
-    *   <li>http           - HTTP Version to use, 1.0 or 1.1 (string)</li>
272
-    *   <li>user           - Basic Auth username (string)</li>
273
-    *   <li>pass           - Basic Auth password (string)</li>
274
-    *   <li>proxy_host     - Proxy server host (string)</li>
275
-    *   <li>proxy_port     - Proxy server port (integer)</li>
276
-    *   <li>proxy_user     - Proxy auth username (string)</li>
277
-    *   <li>proxy_pass     - Proxy auth password (string)</li>
278
-    *   <li>timeout        - Connection timeout in seconds (float)</li>
279
-    *   <li>allowRedirects - Whether to follow redirects or not (bool)</li>
280
-    *   <li>maxRedirects   - Max number of redirects to follow (integer)</li>
281
-    *   <li>useBrackets    - Whether to append [] to array variable names (bool)</li>
282
-    *   <li>saveBody       - Whether to save response body in response object property (bool)</li>
283
-    *   <li>readTimeout    - Timeout for reading / writing data over the socket (array (seconds, microseconds))</li>
284
-    *   <li>socketOptions  - Options to pass to Net_Socket object (array)</li>
285
-    * </ul>
286
-    * @access public
287
-    */
288
-    function HTTP_Request($url = '', $params = array())
289
-    {
290
-        $this->_method         =  HTTP_REQUEST_METHOD_GET;
291
-        $this->_http           =  HTTP_REQUEST_HTTP_VER_1_1;
292
-        $this->_requestHeaders = array();
293
-        $this->_postData       = array();
294
-        $this->_body           = null;
295
-
296
-        $this->_user = null;
297
-        $this->_pass = null;
298
-
299
-        $this->_proxy_host = null;
300
-        $this->_proxy_port = null;
301
-        $this->_proxy_user = null;
302
-        $this->_proxy_pass = null;
303
-
304
-        $this->_allowRedirects = false;
305
-        $this->_maxRedirects   = 3;
306
-        $this->_redirects      = 0;
307
-
308
-        $this->_timeout  = null;
309
-        $this->_response = null;
310
-
311
-        foreach ($params as $key => $value) {
312
-            $this->{'_' . $key} = $value;
313
-        }
314
-
315
-        if (!empty($url)) {
316
-            $this->setURL($url);
317
-        }
318
-
319
-        // Default useragent
320
-        $this->addHeader('User-Agent', 'PEAR HTTP_Request class ( http://pear.php.net/ )');
321
-
322
-        // We don't do keep-alives by default
323
-        $this->addHeader('Connection', 'close');
324
-
325
-        // Basic authentication
326
-        if (!empty($this->_user)) {
327
-            $this->addHeader('Authorization', 'Basic ' . base64_encode($this->_user . ':' . $this->_pass));
328
-        }
329
-
330
-        // Proxy authentication (see bug #5913)
331
-        if (!empty($this->_proxy_user)) {
332
-            $this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($this->_proxy_user . ':' . $this->_proxy_pass));
333
-        }
334
-
335
-        // Use gzip encoding if possible
336
-        if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && extension_loaded('zlib')) {
337
-            $this->addHeader('Accept-Encoding', 'gzip');
338
-        }
339
-    }
263
+	/**
264
+	 * Constructor
265
+	 *
266
+	 * Sets up the object
267
+	 * @param    string  The url to fetch/access
268
+	 * @param    array   Associative array of parameters which can have the following keys:
269
+	 * <ul>
270
+	 *   <li>method         - Method to use, GET, POST etc (string)</li>
271
+	 *   <li>http           - HTTP Version to use, 1.0 or 1.1 (string)</li>
272
+	 *   <li>user           - Basic Auth username (string)</li>
273
+	 *   <li>pass           - Basic Auth password (string)</li>
274
+	 *   <li>proxy_host     - Proxy server host (string)</li>
275
+	 *   <li>proxy_port     - Proxy server port (integer)</li>
276
+	 *   <li>proxy_user     - Proxy auth username (string)</li>
277
+	 *   <li>proxy_pass     - Proxy auth password (string)</li>
278
+	 *   <li>timeout        - Connection timeout in seconds (float)</li>
279
+	 *   <li>allowRedirects - Whether to follow redirects or not (bool)</li>
280
+	 *   <li>maxRedirects   - Max number of redirects to follow (integer)</li>
281
+	 *   <li>useBrackets    - Whether to append [] to array variable names (bool)</li>
282
+	 *   <li>saveBody       - Whether to save response body in response object property (bool)</li>
283
+	 *   <li>readTimeout    - Timeout for reading / writing data over the socket (array (seconds, microseconds))</li>
284
+	 *   <li>socketOptions  - Options to pass to Net_Socket object (array)</li>
285
+	 * </ul>
286
+	 * @access public
287
+	 */
288
+	function HTTP_Request($url = '', $params = array())
289
+	{
290
+		$this->_method         =  HTTP_REQUEST_METHOD_GET;
291
+		$this->_http           =  HTTP_REQUEST_HTTP_VER_1_1;
292
+		$this->_requestHeaders = array();
293
+		$this->_postData       = array();
294
+		$this->_body           = null;
295
+
296
+		$this->_user = null;
297
+		$this->_pass = null;
298
+
299
+		$this->_proxy_host = null;
300
+		$this->_proxy_port = null;
301
+		$this->_proxy_user = null;
302
+		$this->_proxy_pass = null;
303
+
304
+		$this->_allowRedirects = false;
305
+		$this->_maxRedirects   = 3;
306
+		$this->_redirects      = 0;
307
+
308
+		$this->_timeout  = null;
309
+		$this->_response = null;
310
+
311
+		foreach ($params as $key => $value) {
312
+			$this->{'_' . $key} = $value;
313
+		}
314
+
315
+		if (!empty($url)) {
316
+			$this->setURL($url);
317
+		}
318
+
319
+		// Default useragent
320
+		$this->addHeader('User-Agent', 'PEAR HTTP_Request class ( http://pear.php.net/ )');
321
+
322
+		// We don't do keep-alives by default
323
+		$this->addHeader('Connection', 'close');
324
+
325
+		// Basic authentication
326
+		if (!empty($this->_user)) {
327
+			$this->addHeader('Authorization', 'Basic ' . base64_encode($this->_user . ':' . $this->_pass));
328
+		}
329
+
330
+		// Proxy authentication (see bug #5913)
331
+		if (!empty($this->_proxy_user)) {
332
+			$this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($this->_proxy_user . ':' . $this->_proxy_pass));
333
+		}
334
+
335
+		// Use gzip encoding if possible
336
+		if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && extension_loaded('zlib')) {
337
+			$this->addHeader('Accept-Encoding', 'gzip');
338
+		}
339
+	}
340 340
     
341
-    /**
342
-    * Generates a Host header for HTTP/1.1 requests
343
-    *
344
-    * @access private
345
-    * @return string
346
-    */
347
-    function _generateHostHeader()
348
-    {
349
-        if ($this->_url->port != 80 AND strcasecmp($this->_url->protocol, 'http') == 0) {
350
-            $host = $this->_url->host . ':' . $this->_url->port;
351
-
352
-        } elseif ($this->_url->port != 443 AND strcasecmp($this->_url->protocol, 'https') == 0) {
353
-            $host = $this->_url->host . ':' . $this->_url->port;
354
-
355
-        } elseif ($this->_url->port == 443 AND strcasecmp($this->_url->protocol, 'https') == 0 AND strpos($this->_url->url, ':443') !== false) {
356
-            $host = $this->_url->host . ':' . $this->_url->port;
341
+	/**
342
+	 * Generates a Host header for HTTP/1.1 requests
343
+	 *
344
+	 * @access private
345
+	 * @return string
346
+	 */
347
+	function _generateHostHeader()
348
+	{
349
+		if ($this->_url->port != 80 AND strcasecmp($this->_url->protocol, 'http') == 0) {
350
+			$host = $this->_url->host . ':' . $this->_url->port;
351
+
352
+		} elseif ($this->_url->port != 443 AND strcasecmp($this->_url->protocol, 'https') == 0) {
353
+			$host = $this->_url->host . ':' . $this->_url->port;
354
+
355
+		} elseif ($this->_url->port == 443 AND strcasecmp($this->_url->protocol, 'https') == 0 AND strpos($this->_url->url, ':443') !== false) {
356
+			$host = $this->_url->host . ':' . $this->_url->port;
357 357
         
358
-        } else {
359
-            $host = $this->_url->host;
360
-        }
358
+		} else {
359
+			$host = $this->_url->host;
360
+		}
361 361
 
362
-        return $host;
363
-    }
362
+		return $host;
363
+	}
364 364
     
365
-    /**
366
-    * Resets the object to its initial state (DEPRECATED).
367
-    * Takes the same parameters as the constructor.
368
-    *
369
-    * @param  string $url    The url to be requested
370
-    * @param  array  $params Associative array of parameters
371
-    *                        (see constructor for details)
372
-    * @access public
373
-    * @deprecated deprecated since 1.2, call the constructor if this is necessary
374
-    */
375
-    function reset($url, $params = array())
376
-    {
377
-        $this->HTTP_Request($url, $params);
378
-    }
379
-
380
-    /**
381
-    * Sets the URL to be requested
382
-    *
383
-    * @param  string The url to be requested
384
-    * @access public
385
-    */
386
-    function setURL($url)
387
-    {
388
-        $this->_url = &new Net_URL($url, $this->_useBrackets);
389
-
390
-        if (!empty($this->_url->user) || !empty($this->_url->pass)) {
391
-            $this->setBasicAuth($this->_url->user, $this->_url->pass);
392
-        }
393
-
394
-        if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http) {
395
-            $this->addHeader('Host', $this->_generateHostHeader());
396
-        }
397
-
398
-        // set '/' instead of empty path rather than check later (see bug #8662)
399
-        if (empty($this->_url->path)) {
400
-            $this->_url->path = '/';
401
-        } 
402
-    }
365
+	/**
366
+	 * Resets the object to its initial state (DEPRECATED).
367
+	 * Takes the same parameters as the constructor.
368
+	 *
369
+	 * @param  string $url    The url to be requested
370
+	 * @param  array  $params Associative array of parameters
371
+	 *                        (see constructor for details)
372
+	 * @access public
373
+	 * @deprecated deprecated since 1.2, call the constructor if this is necessary
374
+	 */
375
+	function reset($url, $params = array())
376
+	{
377
+		$this->HTTP_Request($url, $params);
378
+	}
379
+
380
+	/**
381
+	 * Sets the URL to be requested
382
+	 *
383
+	 * @param  string The url to be requested
384
+	 * @access public
385
+	 */
386
+	function setURL($url)
387
+	{
388
+		$this->_url = &new Net_URL($url, $this->_useBrackets);
389
+
390
+		if (!empty($this->_url->user) || !empty($this->_url->pass)) {
391
+			$this->setBasicAuth($this->_url->user, $this->_url->pass);
392
+		}
393
+
394
+		if (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http) {
395
+			$this->addHeader('Host', $this->_generateHostHeader());
396
+		}
397
+
398
+		// set '/' instead of empty path rather than check later (see bug #8662)
399
+		if (empty($this->_url->path)) {
400
+			$this->_url->path = '/';
401
+		} 
402
+	}
403 403
     
404 404
    /**
405 405
     * Returns the current request URL  
@@ -407,134 +407,134 @@  discard block
 block discarded – undo
407 407
     * @return   string  Current request URL
408 408
     * @access   public
409 409
     */
410
-    function getUrl()
411
-    {
412
-        return empty($this->_url)? '': $this->_url->getUrl();
413
-    }
414
-
415
-    /**
416
-    * Sets a proxy to be used
417
-    *
418
-    * @param string     Proxy host
419
-    * @param int        Proxy port
420
-    * @param string     Proxy username
421
-    * @param string     Proxy password
422
-    * @access public
423
-    */
424
-    function setProxy($host, $port = 8080, $user = null, $pass = null)
425
-    {
426
-        $this->_proxy_host = $host;
427
-        $this->_proxy_port = $port;
428
-        $this->_proxy_user = $user;
429
-        $this->_proxy_pass = $pass;
430
-
431
-        if (!empty($user)) {
432
-            $this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($user . ':' . $pass));
433
-        }
434
-    }
435
-
436
-    /**
437
-    * Sets basic authentication parameters
438
-    *
439
-    * @param string     Username
440
-    * @param string     Password
441
-    */
442
-    function setBasicAuth($user, $pass)
443
-    {
444
-        $this->_user = $user;
445
-        $this->_pass = $pass;
446
-
447
-        $this->addHeader('Authorization', 'Basic ' . base64_encode($user . ':' . $pass));
448
-    }
449
-
450
-    /**
451
-    * Sets the method to be used, GET, POST etc.
452
-    *
453
-    * @param string     Method to use. Use the defined constants for this
454
-    * @access public
455
-    */
456
-    function setMethod($method)
457
-    {
458
-        $this->_method = $method;
459
-    }
460
-
461
-    /**
462
-    * Sets the HTTP version to use, 1.0 or 1.1
463
-    *
464
-    * @param string     Version to use. Use the defined constants for this
465
-    * @access public
466
-    */
467
-    function setHttpVer($http)
468
-    {
469
-        $this->_http = $http;
470
-    }
471
-
472
-    /**
473
-    * Adds a request header
474
-    *
475
-    * @param string     Header name
476
-    * @param string     Header value
477
-    * @access public
478
-    */
479
-    function addHeader($name, $value)
480
-    {
481
-        $this->_requestHeaders[strtolower($name)] = $value;
482
-    }
483
-
484
-    /**
485
-    * Removes a request header
486
-    *
487
-    * @param string     Header name to remove
488
-    * @access public
489
-    */
490
-    function removeHeader($name)
491
-    {
492
-        if (isset($this->_requestHeaders[strtolower($name)])) {
493
-            unset($this->_requestHeaders[strtolower($name)]);
494
-        }
495
-    }
496
-
497
-    /**
498
-    * Adds a querystring parameter
499
-    *
500
-    * @param string     Querystring parameter name
501
-    * @param string     Querystring parameter value
502
-    * @param bool       Whether the value is already urlencoded or not, default = not
503
-    * @access public
504
-    */
505
-    function addQueryString($name, $value, $preencoded = false)
506
-    {
507
-        $this->_url->addQueryString($name, $value, $preencoded);
508
-    }    
410
+	function getUrl()
411
+	{
412
+		return empty($this->_url)? '': $this->_url->getUrl();
413
+	}
414
+
415
+	/**
416
+	 * Sets a proxy to be used
417
+	 *
418
+	 * @param string     Proxy host
419
+	 * @param int        Proxy port
420
+	 * @param string     Proxy username
421
+	 * @param string     Proxy password
422
+	 * @access public
423
+	 */
424
+	function setProxy($host, $port = 8080, $user = null, $pass = null)
425
+	{
426
+		$this->_proxy_host = $host;
427
+		$this->_proxy_port = $port;
428
+		$this->_proxy_user = $user;
429
+		$this->_proxy_pass = $pass;
430
+
431
+		if (!empty($user)) {
432
+			$this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($user . ':' . $pass));
433
+		}
434
+	}
435
+
436
+	/**
437
+	 * Sets basic authentication parameters
438
+	 *
439
+	 * @param string     Username
440
+	 * @param string     Password
441
+	 */
442
+	function setBasicAuth($user, $pass)
443
+	{
444
+		$this->_user = $user;
445
+		$this->_pass = $pass;
446
+
447
+		$this->addHeader('Authorization', 'Basic ' . base64_encode($user . ':' . $pass));
448
+	}
449
+
450
+	/**
451
+	 * Sets the method to be used, GET, POST etc.
452
+	 *
453
+	 * @param string     Method to use. Use the defined constants for this
454
+	 * @access public
455
+	 */
456
+	function setMethod($method)
457
+	{
458
+		$this->_method = $method;
459
+	}
460
+
461
+	/**
462
+	 * Sets the HTTP version to use, 1.0 or 1.1
463
+	 *
464
+	 * @param string     Version to use. Use the defined constants for this
465
+	 * @access public
466
+	 */
467
+	function setHttpVer($http)
468
+	{
469
+		$this->_http = $http;
470
+	}
471
+
472
+	/**
473
+	 * Adds a request header
474
+	 *
475
+	 * @param string     Header name
476
+	 * @param string     Header value
477
+	 * @access public
478
+	 */
479
+	function addHeader($name, $value)
480
+	{
481
+		$this->_requestHeaders[strtolower($name)] = $value;
482
+	}
483
+
484
+	/**
485
+	 * Removes a request header
486
+	 *
487
+	 * @param string     Header name to remove
488
+	 * @access public
489
+	 */
490
+	function removeHeader($name)
491
+	{
492
+		if (isset($this->_requestHeaders[strtolower($name)])) {
493
+			unset($this->_requestHeaders[strtolower($name)]);
494
+		}
495
+	}
496
+
497
+	/**
498
+	 * Adds a querystring parameter
499
+	 *
500
+	 * @param string     Querystring parameter name
501
+	 * @param string     Querystring parameter value
502
+	 * @param bool       Whether the value is already urlencoded or not, default = not
503
+	 * @access public
504
+	 */
505
+	function addQueryString($name, $value, $preencoded = false)
506
+	{
507
+		$this->_url->addQueryString($name, $value, $preencoded);
508
+	}    
509 509
     
510
-    /**
511
-    * Sets the querystring to literally what you supply
512
-    *
513
-    * @param string     The querystring data. Should be of the format foo=bar&x=y etc
514
-    * @param bool       Whether data is already urlencoded or not, default = already encoded
515
-    * @access public
516
-    */
517
-    function addRawQueryString($querystring, $preencoded = true)
518
-    {
519
-        $this->_url->addRawQueryString($querystring, $preencoded);
520
-    }
521
-
522
-    /**
523
-    * Adds postdata items
524
-    *
525
-    * @param string     Post data name
526
-    * @param string     Post data value
527
-    * @param bool       Whether data is already urlencoded or not, default = not
528
-    * @access public
529
-    */
530
-    function addPostData($name, $value, $preencoded = false)
531
-    {
532
-        if ($preencoded) {
533
-            $this->_postData[$name] = $value;
534
-        } else {
535
-            $this->_postData[$name] = $this->_arrayMapRecursive('urlencode', $value);
536
-        }
537
-    }
510
+	/**
511
+	 * Sets the querystring to literally what you supply
512
+	 *
513
+	 * @param string     The querystring data. Should be of the format foo=bar&x=y etc
514
+	 * @param bool       Whether data is already urlencoded or not, default = already encoded
515
+	 * @access public
516
+	 */
517
+	function addRawQueryString($querystring, $preencoded = true)
518
+	{
519
+		$this->_url->addRawQueryString($querystring, $preencoded);
520
+	}
521
+
522
+	/**
523
+	 * Adds postdata items
524
+	 *
525
+	 * @param string     Post data name
526
+	 * @param string     Post data value
527
+	 * @param bool       Whether data is already urlencoded or not, default = not
528
+	 * @access public
529
+	 */
530
+	function addPostData($name, $value, $preencoded = false)
531
+	{
532
+		if ($preencoded) {
533
+			$this->_postData[$name] = $value;
534
+		} else {
535
+			$this->_postData[$name] = $this->_arrayMapRecursive('urlencode', $value);
536
+		}
537
+	}
538 538
 
539 539
    /**
540 540
     * Recursively applies the callback function to the value
@@ -544,18 +544,18 @@  discard block
 block discarded – undo
544 544
     * @access   private
545 545
     * @return   mixed   Processed value
546 546
     */
547
-    function _arrayMapRecursive($callback, $value)
548
-    {
549
-        if (!is_array($value)) {
550
-            return call_user_func($callback, $value);
551
-        } else {
552
-            $map = array();
553
-            foreach ($value as $k => $v) {
554
-                $map[$k] = $this->_arrayMapRecursive($callback, $v);
555
-            }
556
-            return $map;
557
-        }
558
-    }
547
+	function _arrayMapRecursive($callback, $value)
548
+	{
549
+		if (!is_array($value)) {
550
+			return call_user_func($callback, $value);
551
+		} else {
552
+			$map = array();
553
+			foreach ($value as $k => $v) {
554
+				$map[$k] = $this->_arrayMapRecursive($callback, $v);
555
+			}
556
+			return $map;
557
+		}
558
+	}
559 559
 
560 560
    /**
561 561
     * Adds a file to upload
@@ -569,37 +569,37 @@  discard block
 block discarded – undo
569 569
     * @return bool      true on success
570 570
     * @throws PEAR_Error
571 571
     */
572
-    function addFile($inputName, $fileName, $contentType = 'application/octet-stream')
573
-    {
574
-        if (!is_array($fileName) && !is_readable($fileName)) {
575
-            return PEAR::raiseError("File '{$fileName}' is not readable");
576
-        } elseif (is_array($fileName)) {
577
-            foreach ($fileName as $name) {
578
-                if (!is_readable($name)) {
579
-                    return PEAR::raiseError("File '{$name}' is not readable");
580
-                }
581
-            }
582
-        }
583
-        $this->addHeader('Content-Type', 'multipart/form-data');
584
-        $this->_postFiles[$inputName] = array(
585
-            'name' => $fileName,
586
-            'type' => $contentType
587
-        );
588
-        return true;
589
-    }
590
-
591
-    /**
592
-    * Adds raw postdata (DEPRECATED)
593
-    *
594
-    * @param string     The data
595
-    * @param bool       Whether data is preencoded or not, default = already encoded
596
-    * @access public
597
-    * @deprecated       deprecated since 1.3.0, method setBody() should be used instead
598
-    */
599
-    function addRawPostData($postdata, $preencoded = true)
600
-    {
601
-        $this->_body = $preencoded ? $postdata : urlencode($postdata);
602
-    }
572
+	function addFile($inputName, $fileName, $contentType = 'application/octet-stream')
573
+	{
574
+		if (!is_array($fileName) && !is_readable($fileName)) {
575
+			return PEAR::raiseError("File '{$fileName}' is not readable");
576
+		} elseif (is_array($fileName)) {
577
+			foreach ($fileName as $name) {
578
+				if (!is_readable($name)) {
579
+					return PEAR::raiseError("File '{$name}' is not readable");
580
+				}
581
+			}
582
+		}
583
+		$this->addHeader('Content-Type', 'multipart/form-data');
584
+		$this->_postFiles[$inputName] = array(
585
+			'name' => $fileName,
586
+			'type' => $contentType
587
+		);
588
+		return true;
589
+	}
590
+
591
+	/**
592
+	 * Adds raw postdata (DEPRECATED)
593
+	 *
594
+	 * @param string     The data
595
+	 * @param bool       Whether data is preencoded or not, default = already encoded
596
+	 * @access public
597
+	 * @deprecated       deprecated since 1.3.0, method setBody() should be used instead
598
+	 */
599
+	function addRawPostData($postdata, $preencoded = true)
600
+	{
601
+		$this->_body = $preencoded ? $postdata : urlencode($postdata);
602
+	}
603 603
 
604 604
    /**
605 605
     * Sets the request body (for POST, PUT and similar requests)
@@ -607,370 +607,370 @@  discard block
 block discarded – undo
607 607
     * @param    string  Request body
608 608
     * @access   public
609 609
     */
610
-    function setBody($body)
611
-    {
612
-        $this->_body = $body;
613
-    }
614
-
615
-    /**
616
-    * Clears any postdata that has been added (DEPRECATED). 
617
-    * 
618
-    * Useful for multiple request scenarios.
619
-    *
620
-    * @access public
621
-    * @deprecated deprecated since 1.2
622
-    */
623
-    function clearPostData()
624
-    {
625
-        $this->_postData = null;
626
-    }
627
-
628
-    /**
629
-    * Appends a cookie to "Cookie:" header
630
-    * 
631
-    * @param string $name cookie name
632
-    * @param string $value cookie value
633
-    * @access public
634
-    */
635
-    function addCookie($name, $value)
636
-    {
637
-        $cookies = isset($this->_requestHeaders['cookie']) ? $this->_requestHeaders['cookie']. '; ' : '';
638
-        $this->addHeader('Cookie', $cookies . $name . '=' . $value);
639
-    }
610
+	function setBody($body)
611
+	{
612
+		$this->_body = $body;
613
+	}
614
+
615
+	/**
616
+	 * Clears any postdata that has been added (DEPRECATED). 
617
+	 * 
618
+	 * Useful for multiple request scenarios.
619
+	 *
620
+	 * @access public
621
+	 * @deprecated deprecated since 1.2
622
+	 */
623
+	function clearPostData()
624
+	{
625
+		$this->_postData = null;
626
+	}
627
+
628
+	/**
629
+	 * Appends a cookie to "Cookie:" header
630
+	 * 
631
+	 * @param string $name cookie name
632
+	 * @param string $value cookie value
633
+	 * @access public
634
+	 */
635
+	function addCookie($name, $value)
636
+	{
637
+		$cookies = isset($this->_requestHeaders['cookie']) ? $this->_requestHeaders['cookie']. '; ' : '';
638
+		$this->addHeader('Cookie', $cookies . $name . '=' . $value);
639
+	}
640 640
     
641
-    /**
642
-    * Clears any cookies that have been added (DEPRECATED). 
643
-    * 
644
-    * Useful for multiple request scenarios
645
-    *
646
-    * @access public
647
-    * @deprecated deprecated since 1.2
648
-    */
649
-    function clearCookies()
650
-    {
651
-        $this->removeHeader('Cookie');
652
-    }
653
-
654
-    /**
655
-    * Sends the request
656
-    *
657
-    * @access public
658
-    * @param  bool   Whether to store response body in Response object property,
659
-    *                set this to false if downloading a LARGE file and using a Listener
660
-    * @return mixed  PEAR error on error, true otherwise
661
-    */
662
-    function sendRequest($saveBody = true)
663
-    {
664
-        if (!is_a($this->_url, 'Net_URL')) {
665
-            return PEAR::raiseError('No URL given.');
666
-        }
667
-
668
-        $host = isset($this->_proxy_host) ? $this->_proxy_host : $this->_url->host;
669
-        $port = isset($this->_proxy_port) ? $this->_proxy_port : $this->_url->port;
670
-
671
-        // 4.3.0 supports SSL connections using OpenSSL. The function test determines
672
-        // we running on at least 4.3.0
673
-        if (strcasecmp($this->_url->protocol, 'https') == 0 AND function_exists('file_get_contents') AND extension_loaded('openssl')) {
674
-            if (isset($this->_proxy_host)) {
675
-                return PEAR::raiseError('HTTPS proxies are not supported.');
676
-            }
677
-            $host = 'ssl://' . $host;
678
-        }
679
-
680
-        // magic quotes may fuck up file uploads and chunked response processing
681
-        $magicQuotes = ini_get('magic_quotes_runtime');
682
-        ini_set('magic_quotes_runtime', false);
683
-
684
-        // RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive 
685
-        // connection token to a proxy server...
686
-        if (isset($this->_proxy_host) && !empty($this->_requestHeaders['connection']) &&
687
-            'Keep-Alive' == $this->_requestHeaders['connection'])
688
-        {
689
-            $this->removeHeader('connection');
690
-        }
691
-
692
-        $keepAlive = (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && empty($this->_requestHeaders['connection'])) ||
693
-                     (!empty($this->_requestHeaders['connection']) && 'Keep-Alive' == $this->_requestHeaders['connection']);
694
-        $sockets   = &PEAR::getStaticProperty('HTTP_Request', 'sockets');
695
-        $sockKey   = $host . ':' . $port;
696
-        unset($this->_sock);
697
-
698
-        // There is a connected socket in the "static" property?
699
-        if ($keepAlive && !empty($sockets[$sockKey]) &&
700
-            !empty($sockets[$sockKey]->fp)) 
701
-        {
702
-            $this->_sock =& $sockets[$sockKey];
703
-            $err = null;
704
-        } else {
705
-            $this->_notify('connect');
706
-            $this->_sock =& new Net_Socket();
707
-            $err = $this->_sock->connect($host, $port, null, $this->_timeout, $this->_socketOptions);
708
-        }
709
-        PEAR::isError($err) or $err = $this->_sock->write($this->_buildRequest());
710
-
711
-        if (!PEAR::isError($err)) {
712
-            if (!empty($this->_readTimeout)) {
713
-                $this->_sock->setTimeout($this->_readTimeout[0], $this->_readTimeout[1]);
714
-            }
715
-
716
-            $this->_notify('sentRequest');
717
-
718
-            // Read the response
719
-            $this->_response = &new HTTP_Response($this->_sock, $this->_listeners);
720
-            $err = $this->_response->process(
721
-                $this->_saveBody && $saveBody,
722
-                HTTP_REQUEST_METHOD_HEAD != $this->_method
723
-            );
724
-
725
-            if ($keepAlive) {
726
-                $keepAlive = (isset($this->_response->_headers['content-length'])
727
-                              || (isset($this->_response->_headers['transfer-encoding'])
728
-                                  && strtolower($this->_response->_headers['transfer-encoding']) == 'chunked'));
729
-                if ($keepAlive) {
730
-                    if (isset($this->_response->_headers['connection'])) {
731
-                        $keepAlive = strtolower($this->_response->_headers['connection']) == 'keep-alive';
732
-                    } else {
733
-                        $keepAlive = 'HTTP/'.HTTP_REQUEST_HTTP_VER_1_1 == $this->_response->_protocol;
734
-                    }
735
-                }
736
-            }
737
-        }
738
-
739
-        ini_set('magic_quotes_runtime', $magicQuotes);
740
-
741
-        if (PEAR::isError($err)) {
742
-            return $err;
743
-        }
744
-
745
-        if (!$keepAlive) {
746
-            $this->disconnect();
747
-        // Store the connected socket in "static" property
748
-        } elseif (empty($sockets[$sockKey]) || empty($sockets[$sockKey]->fp)) {
749
-            $sockets[$sockKey] =& $this->_sock;
750
-        }
751
-
752
-        // Check for redirection
753
-        if (    $this->_allowRedirects
754
-            AND $this->_redirects <= $this->_maxRedirects
755
-            AND $this->getResponseCode() > 300
756
-            AND $this->getResponseCode() < 399
757
-            AND !empty($this->_response->_headers['location'])) {
641
+	/**
642
+	 * Clears any cookies that have been added (DEPRECATED). 
643
+	 * 
644
+	 * Useful for multiple request scenarios
645
+	 *
646
+	 * @access public
647
+	 * @deprecated deprecated since 1.2
648
+	 */
649
+	function clearCookies()
650
+	{
651
+		$this->removeHeader('Cookie');
652
+	}
653
+
654
+	/**
655
+	 * Sends the request
656
+	 *
657
+	 * @access public
658
+	 * @param  bool   Whether to store response body in Response object property,
659
+	 *                set this to false if downloading a LARGE file and using a Listener
660
+	 * @return mixed  PEAR error on error, true otherwise
661
+	 */
662
+	function sendRequest($saveBody = true)
663
+	{
664
+		if (!is_a($this->_url, 'Net_URL')) {
665
+			return PEAR::raiseError('No URL given.');
666
+		}
667
+
668
+		$host = isset($this->_proxy_host) ? $this->_proxy_host : $this->_url->host;
669
+		$port = isset($this->_proxy_port) ? $this->_proxy_port : $this->_url->port;
670
+
671
+		// 4.3.0 supports SSL connections using OpenSSL. The function test determines
672
+		// we running on at least 4.3.0
673
+		if (strcasecmp($this->_url->protocol, 'https') == 0 AND function_exists('file_get_contents') AND extension_loaded('openssl')) {
674
+			if (isset($this->_proxy_host)) {
675
+				return PEAR::raiseError('HTTPS proxies are not supported.');
676
+			}
677
+			$host = 'ssl://' . $host;
678
+		}
679
+
680
+		// magic quotes may fuck up file uploads and chunked response processing
681
+		$magicQuotes = ini_get('magic_quotes_runtime');
682
+		ini_set('magic_quotes_runtime', false);
683
+
684
+		// RFC 2068, section 19.7.1: A client MUST NOT send the Keep-Alive 
685
+		// connection token to a proxy server...
686
+		if (isset($this->_proxy_host) && !empty($this->_requestHeaders['connection']) &&
687
+			'Keep-Alive' == $this->_requestHeaders['connection'])
688
+		{
689
+			$this->removeHeader('connection');
690
+		}
691
+
692
+		$keepAlive = (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && empty($this->_requestHeaders['connection'])) ||
693
+					 (!empty($this->_requestHeaders['connection']) && 'Keep-Alive' == $this->_requestHeaders['connection']);
694
+		$sockets   = &PEAR::getStaticProperty('HTTP_Request', 'sockets');
695
+		$sockKey   = $host . ':' . $port;
696
+		unset($this->_sock);
697
+
698
+		// There is a connected socket in the "static" property?
699
+		if ($keepAlive && !empty($sockets[$sockKey]) &&
700
+			!empty($sockets[$sockKey]->fp)) 
701
+		{
702
+			$this->_sock =& $sockets[$sockKey];
703
+			$err = null;
704
+		} else {
705
+			$this->_notify('connect');
706
+			$this->_sock =& new Net_Socket();
707
+			$err = $this->_sock->connect($host, $port, null, $this->_timeout, $this->_socketOptions);
708
+		}
709
+		PEAR::isError($err) or $err = $this->_sock->write($this->_buildRequest());
710
+
711
+		if (!PEAR::isError($err)) {
712
+			if (!empty($this->_readTimeout)) {
713
+				$this->_sock->setTimeout($this->_readTimeout[0], $this->_readTimeout[1]);
714
+			}
715
+
716
+			$this->_notify('sentRequest');
717
+
718
+			// Read the response
719
+			$this->_response = &new HTTP_Response($this->_sock, $this->_listeners);
720
+			$err = $this->_response->process(
721
+				$this->_saveBody && $saveBody,
722
+				HTTP_REQUEST_METHOD_HEAD != $this->_method
723
+			);
724
+
725
+			if ($keepAlive) {
726
+				$keepAlive = (isset($this->_response->_headers['content-length'])
727
+							  || (isset($this->_response->_headers['transfer-encoding'])
728
+								  && strtolower($this->_response->_headers['transfer-encoding']) == 'chunked'));
729
+				if ($keepAlive) {
730
+					if (isset($this->_response->_headers['connection'])) {
731
+						$keepAlive = strtolower($this->_response->_headers['connection']) == 'keep-alive';
732
+					} else {
733
+						$keepAlive = 'HTTP/'.HTTP_REQUEST_HTTP_VER_1_1 == $this->_response->_protocol;
734
+					}
735
+				}
736
+			}
737
+		}
738
+
739
+		ini_set('magic_quotes_runtime', $magicQuotes);
740
+
741
+		if (PEAR::isError($err)) {
742
+			return $err;
743
+		}
744
+
745
+		if (!$keepAlive) {
746
+			$this->disconnect();
747
+		// Store the connected socket in "static" property
748
+		} elseif (empty($sockets[$sockKey]) || empty($sockets[$sockKey]->fp)) {
749
+			$sockets[$sockKey] =& $this->_sock;
750
+		}
751
+
752
+		// Check for redirection
753
+		if (    $this->_allowRedirects
754
+			AND $this->_redirects <= $this->_maxRedirects
755
+			AND $this->getResponseCode() > 300
756
+			AND $this->getResponseCode() < 399
757
+			AND !empty($this->_response->_headers['location'])) {
758 758
 
759 759
             
760
-            $redirect = $this->_response->_headers['location'];
761
-
762
-            // Absolute URL
763
-            if (preg_match('/^https?:\/\//i', $redirect)) {
764
-                $this->_url = &new Net_URL($redirect);
765
-                $this->addHeader('Host', $this->_generateHostHeader());
766
-            // Absolute path
767
-            } elseif ($redirect{0} == '/') {
768
-                $this->_url->path = $redirect;
760
+			$redirect = $this->_response->_headers['location'];
761
+
762
+			// Absolute URL
763
+			if (preg_match('/^https?:\/\//i', $redirect)) {
764
+				$this->_url = &new Net_URL($redirect);
765
+				$this->addHeader('Host', $this->_generateHostHeader());
766
+			// Absolute path
767
+			} elseif ($redirect{0} == '/') {
768
+				$this->_url->path = $redirect;
769 769
             
770
-            // Relative path
771
-            } elseif (substr($redirect, 0, 3) == '../' OR substr($redirect, 0, 2) == './') {
772
-                if (substr($this->_url->path, -1) == '/') {
773
-                    $redirect = $this->_url->path . $redirect;
774
-                } else {
775
-                    $redirect = dirname($this->_url->path) . '/' . $redirect;
776
-                }
777
-                $redirect = Net_URL::resolvePath($redirect);
778
-                $this->_url->path = $redirect;
770
+			// Relative path
771
+			} elseif (substr($redirect, 0, 3) == '../' OR substr($redirect, 0, 2) == './') {
772
+				if (substr($this->_url->path, -1) == '/') {
773
+					$redirect = $this->_url->path . $redirect;
774
+				} else {
775
+					$redirect = dirname($this->_url->path) . '/' . $redirect;
776
+				}
777
+				$redirect = Net_URL::resolvePath($redirect);
778
+				$this->_url->path = $redirect;
779 779
                 
780
-            // Filename, no path
781
-            } else {
782
-                if (substr($this->_url->path, -1) == '/') {
783
-                    $redirect = $this->_url->path . $redirect;
784
-                } else {
785
-                    $redirect = dirname($this->_url->path) . '/' . $redirect;
786
-                }
787
-                $this->_url->path = $redirect;
788
-            }
789
-
790
-            $this->_redirects++;
791
-            return $this->sendRequest($saveBody);
792
-
793
-        // Too many redirects
794
-        } elseif ($this->_allowRedirects AND $this->_redirects > $this->_maxRedirects) {
795
-            return PEAR::raiseError('Too many redirects');
796
-        }
797
-
798
-        return true;
799
-    }
800
-
801
-    /**
802
-     * Disconnect the socket, if connected. Only useful if using Keep-Alive.
803
-     *
804
-     * @access public
805
-     */
806
-    function disconnect()
807
-    {
808
-        if (!empty($this->_sock) && !empty($this->_sock->fp)) {
809
-            $this->_notify('disconnect');
810
-            $this->_sock->disconnect();
811
-        }
812
-    }
813
-
814
-    /**
815
-    * Returns the response code
816
-    *
817
-    * @access public
818
-    * @return mixed     Response code, false if not set
819
-    */
820
-    function getResponseCode()
821
-    {
822
-        return isset($this->_response->_code) ? $this->_response->_code : false;
823
-    }
824
-
825
-    /**
826
-    * Returns either the named header or all if no name given
827
-    *
828
-    * @access public
829
-    * @param string     The header name to return, do not set to get all headers
830
-    * @return mixed     either the value of $headername (false if header is not present)
831
-    *                   or an array of all headers
832
-    */
833
-    function getResponseHeader($headername = null)
834
-    {
835
-        if (!isset($headername)) {
836
-            return isset($this->_response->_headers)? $this->_response->_headers: array();
837
-        } else {
838
-            $headername = strtolower($headername);
839
-            return isset($this->_response->_headers[$headername]) ? $this->_response->_headers[$headername] : false;
840
-        }
841
-    }
842
-
843
-    /**
844
-    * Returns the body of the response
845
-    *
846
-    * @access public
847
-    * @return mixed     response body, false if not set
848
-    */
849
-    function getResponseBody()
850
-    {
851
-        return isset($this->_response->_body) ? $this->_response->_body : false;
852
-    }
853
-
854
-    /**
855
-    * Returns cookies set in response
856
-    * 
857
-    * @access public
858
-    * @return mixed     array of response cookies, false if none are present
859
-    */
860
-    function getResponseCookies()
861
-    {
862
-        return isset($this->_response->_cookies) ? $this->_response->_cookies : false;
863
-    }
864
-
865
-    /**
866
-    * Builds the request string
867
-    *
868
-    * @access private
869
-    * @return string The request string
870
-    */
871
-    function _buildRequest()
872
-    {
873
-        $separator = ini_get('arg_separator.output');
874
-        ini_set('arg_separator.output', '&');
875
-        $querystring = ($querystring = $this->_url->getQueryString()) ? '?' . $querystring : '';
876
-        ini_set('arg_separator.output', $separator);
877
-
878
-        $host = isset($this->_proxy_host) ? $this->_url->protocol . '://' . $this->_url->host : '';
879
-        $port = (isset($this->_proxy_host) AND $this->_url->port != 80) ? ':' . $this->_url->port : '';
880
-        $path = $this->_url->path . $querystring;
881
-        $url  = $host . $port . $path;
882
-
883
-        $request = $this->_method . ' ' . $url . ' HTTP/' . $this->_http . "\r\n";
884
-
885
-        if (in_array($this->_method, $this->_bodyDisallowed) ||
886
-            (empty($this->_body) && (HTTP_REQUEST_METHOD_POST != $this->_method ||
887
-             (empty($this->_postData) && empty($this->_postFiles)))))
888
-        {
889
-            $this->removeHeader('Content-Type');
890
-        } else {
891
-            if (empty($this->_requestHeaders['content-type'])) {
892
-                // Add default content-type
893
-                $this->addHeader('Content-Type', 'application/x-www-form-urlencoded');
894
-            } elseif ('multipart/form-data' == $this->_requestHeaders['content-type']) {
895
-                $boundary = 'HTTP_Request_' . md5(uniqid('request') . microtime());
896
-                $this->addHeader('Content-Type', 'multipart/form-data; boundary=' . $boundary);
897
-            }
898
-        }
899
-
900
-        // Request Headers
901
-        if (!empty($this->_requestHeaders)) {
902
-            foreach ($this->_requestHeaders as $name => $value) {
903
-                $canonicalName = implode('-', array_map('ucfirst', explode('-', $name)));
904
-                $request      .= $canonicalName . ': ' . $value . "\r\n";
905
-            }
906
-        }
907
-
908
-        // No post data or wrong method, so simply add a final CRLF
909
-        if (in_array($this->_method, $this->_bodyDisallowed) || 
910
-            (HTTP_REQUEST_METHOD_POST != $this->_method && empty($this->_body))) {
911
-
912
-            $request .= "\r\n";
913
-
914
-        // Post data if it's an array
915
-        } elseif (HTTP_REQUEST_METHOD_POST == $this->_method && 
916
-                  (!empty($this->_postData) || !empty($this->_postFiles))) {
917
-
918
-            // "normal" POST request
919
-            if (!isset($boundary)) {
920
-                $postdata = implode('&', array_map(
921
-                    create_function('$a', 'return $a[0] . \'=\' . $a[1];'), 
922
-                    $this->_flattenArray('', $this->_postData)
923
-                ));
924
-
925
-            // multipart request, probably with file uploads
926
-            } else {
927
-                $postdata = '';
928
-                if (!empty($this->_postData)) {
929
-                    $flatData = $this->_flattenArray('', $this->_postData);
930
-                    foreach ($flatData as $item) {
931
-                        $postdata .= '--' . $boundary . "\r\n";
932
-                        $postdata .= 'Content-Disposition: form-data; name="' . $item[0] . '"';
933
-                        $postdata .= "\r\n\r\n" . urldecode($item[1]) . "\r\n";
934
-                    }
935
-                }
936
-                foreach ($this->_postFiles as $name => $value) {
937
-                    if (is_array($value['name'])) {
938
-                        $varname       = $name . ($this->_useBrackets? '[]': '');
939
-                    } else {
940
-                        $varname       = $name;
941
-                        $value['name'] = array($value['name']);
942
-                    }
943
-                    foreach ($value['name'] as $key => $filename) {
944
-                        $fp   = fopen($filename, 'r');
945
-                        $data = fread($fp, filesize($filename));
946
-                        fclose($fp);
947
-                        $basename = basename($filename);
948
-                        $type     = is_array($value['type'])? @$value['type'][$key]: $value['type'];
949
-
950
-                        $postdata .= '--' . $boundary . "\r\n";
951
-                        $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"';
952
-                        $postdata .= "\r\nContent-Type: " . $type;
953
-                        $postdata .= "\r\n\r\n" . $data . "\r\n";
954
-                    }
955
-                }
956
-                $postdata .= '--' . $boundary . "--\r\n";
957
-            }
958
-            $request .= 'Content-Length: ' .
959
-                        (HTTP_REQUEST_MBSTRING? mb_strlen($postdata, 'iso-8859-1'): strlen($postdata)) .
960
-                        "\r\n\r\n";
961
-            $request .= $postdata;
962
-
963
-        // Explicitly set request body
964
-        } elseif (!empty($this->_body)) {
965
-
966
-            $request .= 'Content-Length: ' .
967
-                        (HTTP_REQUEST_MBSTRING? mb_strlen($this->_body, 'iso-8859-1'): strlen($this->_body)) .
968
-                        "\r\n\r\n";
969
-            $request .= $this->_body;
970
-        }
780
+			// Filename, no path
781
+			} else {
782
+				if (substr($this->_url->path, -1) == '/') {
783
+					$redirect = $this->_url->path . $redirect;
784
+				} else {
785
+					$redirect = dirname($this->_url->path) . '/' . $redirect;
786
+				}
787
+				$this->_url->path = $redirect;
788
+			}
789
+
790
+			$this->_redirects++;
791
+			return $this->sendRequest($saveBody);
792
+
793
+		// Too many redirects
794
+		} elseif ($this->_allowRedirects AND $this->_redirects > $this->_maxRedirects) {
795
+			return PEAR::raiseError('Too many redirects');
796
+		}
797
+
798
+		return true;
799
+	}
800
+
801
+	/**
802
+	 * Disconnect the socket, if connected. Only useful if using Keep-Alive.
803
+	 *
804
+	 * @access public
805
+	 */
806
+	function disconnect()
807
+	{
808
+		if (!empty($this->_sock) && !empty($this->_sock->fp)) {
809
+			$this->_notify('disconnect');
810
+			$this->_sock->disconnect();
811
+		}
812
+	}
813
+
814
+	/**
815
+	 * Returns the response code
816
+	 *
817
+	 * @access public
818
+	 * @return mixed     Response code, false if not set
819
+	 */
820
+	function getResponseCode()
821
+	{
822
+		return isset($this->_response->_code) ? $this->_response->_code : false;
823
+	}
824
+
825
+	/**
826
+	 * Returns either the named header or all if no name given
827
+	 *
828
+	 * @access public
829
+	 * @param string     The header name to return, do not set to get all headers
830
+	 * @return mixed     either the value of $headername (false if header is not present)
831
+	 *                   or an array of all headers
832
+	 */
833
+	function getResponseHeader($headername = null)
834
+	{
835
+		if (!isset($headername)) {
836
+			return isset($this->_response->_headers)? $this->_response->_headers: array();
837
+		} else {
838
+			$headername = strtolower($headername);
839
+			return isset($this->_response->_headers[$headername]) ? $this->_response->_headers[$headername] : false;
840
+		}
841
+	}
842
+
843
+	/**
844
+	 * Returns the body of the response
845
+	 *
846
+	 * @access public
847
+	 * @return mixed     response body, false if not set
848
+	 */
849
+	function getResponseBody()
850
+	{
851
+		return isset($this->_response->_body) ? $this->_response->_body : false;
852
+	}
853
+
854
+	/**
855
+	 * Returns cookies set in response
856
+	 * 
857
+	 * @access public
858
+	 * @return mixed     array of response cookies, false if none are present
859
+	 */
860
+	function getResponseCookies()
861
+	{
862
+		return isset($this->_response->_cookies) ? $this->_response->_cookies : false;
863
+	}
864
+
865
+	/**
866
+	 * Builds the request string
867
+	 *
868
+	 * @access private
869
+	 * @return string The request string
870
+	 */
871
+	function _buildRequest()
872
+	{
873
+		$separator = ini_get('arg_separator.output');
874
+		ini_set('arg_separator.output', '&');
875
+		$querystring = ($querystring = $this->_url->getQueryString()) ? '?' . $querystring : '';
876
+		ini_set('arg_separator.output', $separator);
877
+
878
+		$host = isset($this->_proxy_host) ? $this->_url->protocol . '://' . $this->_url->host : '';
879
+		$port = (isset($this->_proxy_host) AND $this->_url->port != 80) ? ':' . $this->_url->port : '';
880
+		$path = $this->_url->path . $querystring;
881
+		$url  = $host . $port . $path;
882
+
883
+		$request = $this->_method . ' ' . $url . ' HTTP/' . $this->_http . "\r\n";
884
+
885
+		if (in_array($this->_method, $this->_bodyDisallowed) ||
886
+			(empty($this->_body) && (HTTP_REQUEST_METHOD_POST != $this->_method ||
887
+			 (empty($this->_postData) && empty($this->_postFiles)))))
888
+		{
889
+			$this->removeHeader('Content-Type');
890
+		} else {
891
+			if (empty($this->_requestHeaders['content-type'])) {
892
+				// Add default content-type
893
+				$this->addHeader('Content-Type', 'application/x-www-form-urlencoded');
894
+			} elseif ('multipart/form-data' == $this->_requestHeaders['content-type']) {
895
+				$boundary = 'HTTP_Request_' . md5(uniqid('request') . microtime());
896
+				$this->addHeader('Content-Type', 'multipart/form-data; boundary=' . $boundary);
897
+			}
898
+		}
899
+
900
+		// Request Headers
901
+		if (!empty($this->_requestHeaders)) {
902
+			foreach ($this->_requestHeaders as $name => $value) {
903
+				$canonicalName = implode('-', array_map('ucfirst', explode('-', $name)));
904
+				$request      .= $canonicalName . ': ' . $value . "\r\n";
905
+			}
906
+		}
907
+
908
+		// No post data or wrong method, so simply add a final CRLF
909
+		if (in_array($this->_method, $this->_bodyDisallowed) || 
910
+			(HTTP_REQUEST_METHOD_POST != $this->_method && empty($this->_body))) {
911
+
912
+			$request .= "\r\n";
913
+
914
+		// Post data if it's an array
915
+		} elseif (HTTP_REQUEST_METHOD_POST == $this->_method && 
916
+				  (!empty($this->_postData) || !empty($this->_postFiles))) {
917
+
918
+			// "normal" POST request
919
+			if (!isset($boundary)) {
920
+				$postdata = implode('&', array_map(
921
+					create_function('$a', 'return $a[0] . \'=\' . $a[1];'), 
922
+					$this->_flattenArray('', $this->_postData)
923
+				));
924
+
925
+			// multipart request, probably with file uploads
926
+			} else {
927
+				$postdata = '';
928
+				if (!empty($this->_postData)) {
929
+					$flatData = $this->_flattenArray('', $this->_postData);
930
+					foreach ($flatData as $item) {
931
+						$postdata .= '--' . $boundary . "\r\n";
932
+						$postdata .= 'Content-Disposition: form-data; name="' . $item[0] . '"';
933
+						$postdata .= "\r\n\r\n" . urldecode($item[1]) . "\r\n";
934
+					}
935
+				}
936
+				foreach ($this->_postFiles as $name => $value) {
937
+					if (is_array($value['name'])) {
938
+						$varname       = $name . ($this->_useBrackets? '[]': '');
939
+					} else {
940
+						$varname       = $name;
941
+						$value['name'] = array($value['name']);
942
+					}
943
+					foreach ($value['name'] as $key => $filename) {
944
+						$fp   = fopen($filename, 'r');
945
+						$data = fread($fp, filesize($filename));
946
+						fclose($fp);
947
+						$basename = basename($filename);
948
+						$type     = is_array($value['type'])? @$value['type'][$key]: $value['type'];
949
+
950
+						$postdata .= '--' . $boundary . "\r\n";
951
+						$postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"';
952
+						$postdata .= "\r\nContent-Type: " . $type;
953
+						$postdata .= "\r\n\r\n" . $data . "\r\n";
954
+					}
955
+				}
956
+				$postdata .= '--' . $boundary . "--\r\n";
957
+			}
958
+			$request .= 'Content-Length: ' .
959
+						(HTTP_REQUEST_MBSTRING? mb_strlen($postdata, 'iso-8859-1'): strlen($postdata)) .
960
+						"\r\n\r\n";
961
+			$request .= $postdata;
962
+
963
+		// Explicitly set request body
964
+		} elseif (!empty($this->_body)) {
965
+
966
+			$request .= 'Content-Length: ' .
967
+						(HTTP_REQUEST_MBSTRING? mb_strlen($this->_body, 'iso-8859-1'): strlen($this->_body)) .
968
+						"\r\n\r\n";
969
+			$request .= $this->_body;
970
+		}
971 971
         
972
-        return $request;
973
-    }
972
+		return $request;
973
+	}
974 974
 
975 975
    /**
976 976
     * Helper function to change the (probably multidimensional) associative array
@@ -981,25 +981,25 @@  discard block
 block discarded – undo
981 981
     * @return   array   array with the following items: array('item name', 'item value');
982 982
     * @access   private
983 983
     */
984
-    function _flattenArray($name, $values)
985
-    {
986
-        if (!is_array($values)) {
987
-            return array(array($name, $values));
988
-        } else {
989
-            $ret = array();
990
-            foreach ($values as $k => $v) {
991
-                if (empty($name)) {
992
-                    $newName = $k;
993
-                } elseif ($this->_useBrackets) {
994
-                    $newName = $name . '[' . $k . ']';
995
-                } else {
996
-                    $newName = $name;
997
-                }
998
-                $ret = array_merge($ret, $this->_flattenArray($newName, $v));
999
-            }
1000
-            return $ret;
1001
-        }
1002
-    }
984
+	function _flattenArray($name, $values)
985
+	{
986
+		if (!is_array($values)) {
987
+			return array(array($name, $values));
988
+		} else {
989
+			$ret = array();
990
+			foreach ($values as $k => $v) {
991
+				if (empty($name)) {
992
+					$newName = $k;
993
+				} elseif ($this->_useBrackets) {
994
+					$newName = $name . '[' . $k . ']';
995
+				} else {
996
+					$newName = $name;
997
+				}
998
+				$ret = array_merge($ret, $this->_flattenArray($newName, $v));
999
+			}
1000
+			return $ret;
1001
+		}
1002
+	}
1003 1003
 
1004 1004
 
1005 1005
    /**
@@ -1021,14 +1021,14 @@  discard block
 block discarded – undo
1021 1021
     * @return   boolean                 whether the listener was successfully attached
1022 1022
     * @access   public
1023 1023
     */
1024
-    function attach(&$listener)
1025
-    {
1026
-        if (!is_a($listener, 'HTTP_Request_Listener')) {
1027
-            return false;
1028
-        }
1029
-        $this->_listeners[$listener->getId()] =& $listener;
1030
-        return true;
1031
-    }
1024
+	function attach(&$listener)
1025
+	{
1026
+		if (!is_a($listener, 'HTTP_Request_Listener')) {
1027
+			return false;
1028
+		}
1029
+		$this->_listeners[$listener->getId()] =& $listener;
1030
+		return true;
1031
+	}
1032 1032
 
1033 1033
 
1034 1034
    /**
@@ -1038,15 +1038,15 @@  discard block
 block discarded – undo
1038 1038
     * @return   boolean                 whether the listener was successfully detached
1039 1039
     * @access   public
1040 1040
     */
1041
-    function detach(&$listener)
1042
-    {
1043
-        if (!is_a($listener, 'HTTP_Request_Listener') || 
1044
-            !isset($this->_listeners[$listener->getId()])) {
1045
-            return false;
1046
-        }
1047
-        unset($this->_listeners[$listener->getId()]);
1048
-        return true;
1049
-    }
1041
+	function detach(&$listener)
1042
+	{
1043
+		if (!is_a($listener, 'HTTP_Request_Listener') || 
1044
+			!isset($this->_listeners[$listener->getId()])) {
1045
+			return false;
1046
+		}
1047
+		unset($this->_listeners[$listener->getId()]);
1048
+		return true;
1049
+	}
1050 1050
 
1051 1051
 
1052 1052
    /**
@@ -1057,12 +1057,12 @@  discard block
 block discarded – undo
1057 1057
     * @access   private
1058 1058
     * @see      HTTP_Request::attach()
1059 1059
     */
1060
-    function _notify($event, $data = null)
1061
-    {
1062
-        foreach (array_keys($this->_listeners) as $id) {
1063
-            $this->_listeners[$id]->update($this, $event, $data);
1064
-        }
1065
-    }
1060
+	function _notify($event, $data = null)
1061
+	{
1062
+		foreach (array_keys($this->_listeners) as $id) {
1063
+			$this->_listeners[$id]->update($this, $event, $data);
1064
+		}
1065
+	}
1066 1066
 }
1067 1067
 
1068 1068
 
@@ -1077,71 +1077,71 @@  discard block
 block discarded – undo
1077 1077
  */
1078 1078
 class HTTP_Response
1079 1079
 {
1080
-    /**
1081
-    * Socket object
1082
-    * @var Net_Socket
1083
-    */
1084
-    var $_sock;
1085
-
1086
-    /**
1087
-    * Protocol
1088
-    * @var string
1089
-    */
1090
-    var $_protocol;
1080
+	/**
1081
+	 * Socket object
1082
+	 * @var Net_Socket
1083
+	 */
1084
+	var $_sock;
1085
+
1086
+	/**
1087
+	 * Protocol
1088
+	 * @var string
1089
+	 */
1090
+	var $_protocol;
1091 1091
     
1092
-    /**
1093
-    * Return code
1094
-    * @var string
1095
-    */
1096
-    var $_code;
1092
+	/**
1093
+	 * Return code
1094
+	 * @var string
1095
+	 */
1096
+	var $_code;
1097 1097
     
1098
-    /**
1099
-    * Response headers
1100
-    * @var array
1101
-    */
1102
-    var $_headers;
1103
-
1104
-    /**
1105
-    * Cookies set in response  
1106
-    * @var array
1107
-    */
1108
-    var $_cookies;
1109
-
1110
-    /**
1111
-    * Response body
1112
-    * @var string
1113
-    */
1114
-    var $_body = '';
1098
+	/**
1099
+	 * Response headers
1100
+	 * @var array
1101
+	 */
1102
+	var $_headers;
1103
+
1104
+	/**
1105
+	 * Cookies set in response  
1106
+	 * @var array
1107
+	 */
1108
+	var $_cookies;
1109
+
1110
+	/**
1111
+	 * Response body
1112
+	 * @var string
1113
+	 */
1114
+	var $_body = '';
1115 1115
 
1116 1116
    /**
1117 1117
     * Used by _readChunked(): remaining length of the current chunk
1118 1118
     * @var string
1119 1119
     */
1120
-    var $_chunkLength = 0;
1120
+	var $_chunkLength = 0;
1121 1121
 
1122 1122
    /**
1123 1123
     * Attached listeners
1124 1124
     * @var array
1125 1125
     */
1126
-    var $_listeners = array();
1126
+	var $_listeners = array();
1127 1127
 
1128 1128
    /**
1129 1129
     * Bytes left to read from message-body
1130 1130
     * @var null|int
1131 1131
     */
1132
-    var $_toRead;
1132
+	var $_toRead;
1133 1133
 
1134
-    /**
1135
-    * Constructor
1136
-    *
1137
-    * @param  Net_Socket    socket to read the response from
1138
-    * @param  array         listeners attached to request
1139
-    */
1140
-    function HTTP_Response(&$sock, &$listeners)
1141
-    {
1142
-        $this->_sock      =& $sock;
1143
-        $this->_listeners =& $listeners;
1144
-    }
1134
+	/**
1135
+	 * Constructor
1136
+	 *
1137
+	 * @param  Net_Socket    socket to read the response from
1138
+	 * @param  array         listeners attached to request
1139
+	 */
1140
+	function HTTP_Response(&$sock, &$listeners)
1141
+	{
1142
+		$this->_sock      =& $sock;
1143
+		$this->_listeners =& $listeners;
1144
+	}
1145 1145
 
1146 1146
 
1147 1147
    /**
@@ -1159,80 +1159,80 @@  discard block
 block discarded – undo
1159 1159
     * @throws PEAR_Error
1160 1160
     * @return mixed     true on success, PEAR_Error in case of malformed response
1161 1161
     */
1162
-    function process($saveBody = true, $canHaveBody = true)
1163
-    {
1164
-        do {
1165
-            $line = $this->_sock->readLine();
1166
-            if (sscanf($line, 'HTTP/%s %s', $http_version, $returncode) != 2) {
1167
-                return PEAR::raiseError('Malformed response.');
1168
-            } else {
1169
-                $this->_protocol = 'HTTP/' . $http_version;
1170
-                $this->_code     = intval($returncode);
1171
-            }
1172
-            while ('' !== ($header = $this->_sock->readLine())) {
1173
-                $this->_processHeader($header);
1174
-            }
1175
-        } while (100 == $this->_code);
1176
-
1177
-        $this->_notify('gotHeaders', $this->_headers);
1178
-
1179
-        // RFC 2616, section 4.4:
1180
-        // 1. Any response message which "MUST NOT" include a message-body ... 
1181
-        // is always terminated by the first empty line after the header fields 
1182
-        // 3. ... If a message is received with both a
1183
-        // Transfer-Encoding header field and a Content-Length header field,
1184
-        // the latter MUST be ignored.
1185
-        $canHaveBody = $canHaveBody && $this->_code >= 200 && 
1186
-                       $this->_code != 204 && $this->_code != 304;
1187
-
1188
-        // If response body is present, read it and decode
1189
-        $chunked = isset($this->_headers['transfer-encoding']) && ('chunked' == $this->_headers['transfer-encoding']);
1190
-        $gzipped = isset($this->_headers['content-encoding']) && ('gzip' == $this->_headers['content-encoding']);
1191
-        $hasBody = false;
1192
-        if ($canHaveBody && ($chunked || !isset($this->_headers['content-length']) || 
1193
-                0 != $this->_headers['content-length']))
1194
-        {
1195
-            if ($chunked || !isset($this->_headers['content-length'])) {
1196
-                $this->_toRead = null;
1197
-            } else {
1198
-                $this->_toRead = $this->_headers['content-length'];
1199
-            }
1200
-            while (!$this->_sock->eof() && (is_null($this->_toRead) || 0 < $this->_toRead)) {
1201
-                if ($chunked) {
1202
-                    $data = $this->_readChunked();
1203
-                } elseif (is_null($this->_toRead)) {
1204
-                    $data = $this->_sock->read(4096);
1205
-                } else {
1206
-                    $data = $this->_sock->read(min(4096, $this->_toRead));
1207
-                    $this->_toRead -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data);
1208
-                }
1209
-                if ('' == $data) {
1210
-                    break;
1211
-                } else {
1212
-                    $hasBody = true;
1213
-                    if ($saveBody || $gzipped) {
1214
-                        $this->_body .= $data;
1215
-                    }
1216
-                    $this->_notify($gzipped? 'gzTick': 'tick', $data);
1217
-                }
1218
-            }
1219
-        }
1220
-
1221
-        if ($hasBody) {
1222
-            // Uncompress the body if needed
1223
-            if ($gzipped) {
1224
-                $body = $this->_decodeGzip($this->_body);
1225
-                if (PEAR::isError($body)) {
1226
-                    return $body;
1227
-                }
1228
-                $this->_body = $body;
1229
-                $this->_notify('gotBody', $this->_body);
1230
-            } else {
1231
-                $this->_notify('gotBody');
1232
-            }
1233
-        }
1234
-        return true;
1235
-    }
1162
+	function process($saveBody = true, $canHaveBody = true)
1163
+	{
1164
+		do {
1165
+			$line = $this->_sock->readLine();
1166
+			if (sscanf($line, 'HTTP/%s %s', $http_version, $returncode) != 2) {
1167
+				return PEAR::raiseError('Malformed response.');
1168
+			} else {
1169
+				$this->_protocol = 'HTTP/' . $http_version;
1170
+				$this->_code     = intval($returncode);
1171
+			}
1172
+			while ('' !== ($header = $this->_sock->readLine())) {
1173
+				$this->_processHeader($header);
1174
+			}
1175
+		} while (100 == $this->_code);
1176
+
1177
+		$this->_notify('gotHeaders', $this->_headers);
1178
+
1179
+		// RFC 2616, section 4.4:
1180
+		// 1. Any response message which "MUST NOT" include a message-body ... 
1181
+		// is always terminated by the first empty line after the header fields 
1182
+		// 3. ... If a message is received with both a
1183
+		// Transfer-Encoding header field and a Content-Length header field,
1184
+		// the latter MUST be ignored.
1185
+		$canHaveBody = $canHaveBody && $this->_code >= 200 && 
1186
+					   $this->_code != 204 && $this->_code != 304;
1187
+
1188
+		// If response body is present, read it and decode
1189
+		$chunked = isset($this->_headers['transfer-encoding']) && ('chunked' == $this->_headers['transfer-encoding']);
1190
+		$gzipped = isset($this->_headers['content-encoding']) && ('gzip' == $this->_headers['content-encoding']);
1191
+		$hasBody = false;
1192
+		if ($canHaveBody && ($chunked || !isset($this->_headers['content-length']) || 
1193
+				0 != $this->_headers['content-length']))
1194
+		{
1195
+			if ($chunked || !isset($this->_headers['content-length'])) {
1196
+				$this->_toRead = null;
1197
+			} else {
1198
+				$this->_toRead = $this->_headers['content-length'];
1199
+			}
1200
+			while (!$this->_sock->eof() && (is_null($this->_toRead) || 0 < $this->_toRead)) {
1201
+				if ($chunked) {
1202
+					$data = $this->_readChunked();
1203
+				} elseif (is_null($this->_toRead)) {
1204
+					$data = $this->_sock->read(4096);
1205
+				} else {
1206
+					$data = $this->_sock->read(min(4096, $this->_toRead));
1207
+					$this->_toRead -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data);
1208
+				}
1209
+				if ('' == $data) {
1210
+					break;
1211
+				} else {
1212
+					$hasBody = true;
1213
+					if ($saveBody || $gzipped) {
1214
+						$this->_body .= $data;
1215
+					}
1216
+					$this->_notify($gzipped? 'gzTick': 'tick', $data);
1217
+				}
1218
+			}
1219
+		}
1220
+
1221
+		if ($hasBody) {
1222
+			// Uncompress the body if needed
1223
+			if ($gzipped) {
1224
+				$body = $this->_decodeGzip($this->_body);
1225
+				if (PEAR::isError($body)) {
1226
+					return $body;
1227
+				}
1228
+				$this->_body = $body;
1229
+				$this->_notify('gotBody', $this->_body);
1230
+			} else {
1231
+				$this->_notify('gotBody');
1232
+			}
1233
+		}
1234
+		return true;
1235
+	}
1236 1236
 
1237 1237
 
1238 1238
    /**
@@ -1241,25 +1241,25 @@  discard block
 block discarded – undo
1241 1241
     * @access private
1242 1242
     * @param  string    HTTP header
1243 1243
     */
1244
-    function _processHeader($header)
1245
-    {
1246
-        if (false === strpos($header, ':')) {
1247
-            return;
1248
-        }
1249
-        list($headername, $headervalue) = explode(':', $header, 2);
1250
-        $headername  = strtolower($headername);
1251
-        $headervalue = ltrim($headervalue);
1244
+	function _processHeader($header)
1245
+	{
1246
+		if (false === strpos($header, ':')) {
1247
+			return;
1248
+		}
1249
+		list($headername, $headervalue) = explode(':', $header, 2);
1250
+		$headername  = strtolower($headername);
1251
+		$headervalue = ltrim($headervalue);
1252 1252
         
1253
-        if ('set-cookie' != $headername) {
1254
-            if (isset($this->_headers[$headername])) {
1255
-                $this->_headers[$headername] .= ',' . $headervalue;
1256
-            } else {
1257
-                $this->_headers[$headername]  = $headervalue;
1258
-            }
1259
-        } else {
1260
-            $this->_parseCookie($headervalue);
1261
-        }
1262
-    }
1253
+		if ('set-cookie' != $headername) {
1254
+			if (isset($this->_headers[$headername])) {
1255
+				$this->_headers[$headername] .= ',' . $headervalue;
1256
+			} else {
1257
+				$this->_headers[$headername]  = $headervalue;
1258
+			}
1259
+		} else {
1260
+			$this->_parseCookie($headervalue);
1261
+		}
1262
+	}
1263 1263
 
1264 1264
 
1265 1265
    /**
@@ -1268,49 +1268,49 @@  discard block
 block discarded – undo
1268 1268
     * @access private
1269 1269
     * @param  string    value of Set-Cookie header
1270 1270
     */
1271
-    function _parseCookie($headervalue)
1272
-    {
1273
-        $cookie = array(
1274
-            'expires' => null,
1275
-            'domain'  => null,
1276
-            'path'    => null,
1277
-            'secure'  => false
1278
-        );
1279
-
1280
-        // Only a name=value pair
1281
-        if (!strpos($headervalue, ';')) {
1282
-            $pos = strpos($headervalue, '=');
1283
-            $cookie['name']  = trim(substr($headervalue, 0, $pos));
1284
-            $cookie['value'] = trim(substr($headervalue, $pos + 1));
1285
-
1286
-        // Some optional parameters are supplied
1287
-        } else {
1288
-            $elements = explode(';', $headervalue);
1289
-            $pos = strpos($elements[0], '=');
1290
-            $cookie['name']  = trim(substr($elements[0], 0, $pos));
1291
-            $cookie['value'] = trim(substr($elements[0], $pos + 1));
1292
-
1293
-            for ($i = 1; $i < count($elements); $i++) {
1294
-                if (false === strpos($elements[$i], '=')) {
1295
-                    $elName  = trim($elements[$i]);
1296
-                    $elValue = null;
1297
-                } else {
1298
-                    list ($elName, $elValue) = array_map('trim', explode('=', $elements[$i]));
1299
-                }
1300
-                $elName = strtolower($elName);
1301
-                if ('secure' == $elName) {
1302
-                    $cookie['secure'] = true;
1303
-                } elseif ('expires' == $elName) {
1304
-                    $cookie['expires'] = str_replace('"', '', $elValue);
1305
-                } elseif ('path' == $elName || 'domain' == $elName) {
1306
-                    $cookie[$elName] = urldecode($elValue);
1307
-                } else {
1308
-                    $cookie[$elName] = $elValue;
1309
-                }
1310
-            }
1311
-        }
1312
-        $this->_cookies[] = $cookie;
1313
-    }
1271
+	function _parseCookie($headervalue)
1272
+	{
1273
+		$cookie = array(
1274
+			'expires' => null,
1275
+			'domain'  => null,
1276
+			'path'    => null,
1277
+			'secure'  => false
1278
+		);
1279
+
1280
+		// Only a name=value pair
1281
+		if (!strpos($headervalue, ';')) {
1282
+			$pos = strpos($headervalue, '=');
1283
+			$cookie['name']  = trim(substr($headervalue, 0, $pos));
1284
+			$cookie['value'] = trim(substr($headervalue, $pos + 1));
1285
+
1286
+		// Some optional parameters are supplied
1287
+		} else {
1288
+			$elements = explode(';', $headervalue);
1289
+			$pos = strpos($elements[0], '=');
1290
+			$cookie['name']  = trim(substr($elements[0], 0, $pos));
1291
+			$cookie['value'] = trim(substr($elements[0], $pos + 1));
1292
+
1293
+			for ($i = 1; $i < count($elements); $i++) {
1294
+				if (false === strpos($elements[$i], '=')) {
1295
+					$elName  = trim($elements[$i]);
1296
+					$elValue = null;
1297
+				} else {
1298
+					list ($elName, $elValue) = array_map('trim', explode('=', $elements[$i]));
1299
+				}
1300
+				$elName = strtolower($elName);
1301
+				if ('secure' == $elName) {
1302
+					$cookie['secure'] = true;
1303
+				} elseif ('expires' == $elName) {
1304
+					$cookie['expires'] = str_replace('"', '', $elValue);
1305
+				} elseif ('path' == $elName || 'domain' == $elName) {
1306
+					$cookie[$elName] = urldecode($elValue);
1307
+				} else {
1308
+					$cookie[$elName] = $elValue;
1309
+				}
1310
+			}
1311
+		}
1312
+		$this->_cookies[] = $cookie;
1313
+	}
1314 1314
 
1315 1315
 
1316 1316
    /**
@@ -1319,29 +1319,29 @@  discard block
 block discarded – undo
1319 1319
     * @access private
1320 1320
     * @return string
1321 1321
     */
1322
-    function _readChunked()
1323
-    {
1324
-        // at start of the next chunk?
1325
-        if (0 == $this->_chunkLength) {
1326
-            $line = $this->_sock->readLine();
1327
-            if (preg_match('/^([0-9a-f]+)/i', $line, $matches)) {
1328
-                $this->_chunkLength = hexdec($matches[1]); 
1329
-                // Chunk with zero length indicates the end
1330
-                if (0 == $this->_chunkLength) {
1331
-                    $this->_sock->readLine(); // make this an eof()
1332
-                    return '';
1333
-                }
1334
-            } else {
1335
-                return '';
1336
-            }
1337
-        }
1338
-        $data = $this->_sock->read($this->_chunkLength);
1339
-        $this->_chunkLength -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data);
1340
-        if (0 == $this->_chunkLength) {
1341
-            $this->_sock->readLine(); // Trailing CRLF
1342
-        }
1343
-        return $data;
1344
-    }
1322
+	function _readChunked()
1323
+	{
1324
+		// at start of the next chunk?
1325
+		if (0 == $this->_chunkLength) {
1326
+			$line = $this->_sock->readLine();
1327
+			if (preg_match('/^([0-9a-f]+)/i', $line, $matches)) {
1328
+				$this->_chunkLength = hexdec($matches[1]); 
1329
+				// Chunk with zero length indicates the end
1330
+				if (0 == $this->_chunkLength) {
1331
+					$this->_sock->readLine(); // make this an eof()
1332
+					return '';
1333
+				}
1334
+			} else {
1335
+				return '';
1336
+			}
1337
+		}
1338
+		$data = $this->_sock->read($this->_chunkLength);
1339
+		$this->_chunkLength -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data);
1340
+		if (0 == $this->_chunkLength) {
1341
+			$this->_sock->readLine(); // Trailing CRLF
1342
+		}
1343
+		return $data;
1344
+	}
1345 1345
 
1346 1346
 
1347 1347
    /**
@@ -1352,12 +1352,12 @@  discard block
 block discarded – undo
1352 1352
     * @access   private
1353 1353
     * @see HTTP_Request::_notify()
1354 1354
     */
1355
-    function _notify($event, $data = null)
1356
-    {
1357
-        foreach (array_keys($this->_listeners) as $id) {
1358
-            $this->_listeners[$id]->update($this, $event, $data);
1359
-        }
1360
-    }
1355
+	function _notify($event, $data = null)
1356
+	{
1357
+		foreach (array_keys($this->_listeners) as $id) {
1358
+			$this->_listeners[$id]->update($this, $event, $data);
1359
+		}
1360
+	}
1361 1361
 
1362 1362
 
1363 1363
    /**
@@ -1371,91 +1371,91 @@  discard block
 block discarded – undo
1371 1371
     * @param    string  gzip-encoded data
1372 1372
     * @return   string  decoded data
1373 1373
     */
1374
-    function _decodeGzip($data)
1375
-    {
1376
-        if (HTTP_REQUEST_MBSTRING) {
1377
-            $oldEncoding = mb_internal_encoding();
1378
-            mb_internal_encoding('iso-8859-1');
1379
-        }
1380
-        $length = strlen($data);
1381
-        // If it doesn't look like gzip-encoded data, don't bother
1382
-        if (18 > $length || strcmp(substr($data, 0, 2), "\x1f\x8b")) {
1383
-            return $data;
1384
-        }
1385
-        $method = ord(substr($data, 2, 1));
1386
-        if (8 != $method) {
1387
-            return PEAR::raiseError('_decodeGzip(): unknown compression method');
1388
-        }
1389
-        $flags = ord(substr($data, 3, 1));
1390
-        if ($flags & 224) {
1391
-            return PEAR::raiseError('_decodeGzip(): reserved bits are set');
1392
-        }
1393
-
1394
-        // header is 10 bytes minimum. may be longer, though.
1395
-        $headerLength = 10;
1396
-        // extra fields, need to skip 'em
1397
-        if ($flags & 4) {
1398
-            if ($length - $headerLength - 2 < 8) {
1399
-                return PEAR::raiseError('_decodeGzip(): data too short');
1400
-            }
1401
-            $extraLength = unpack('v', substr($data, 10, 2));
1402
-            if ($length - $headerLength - 2 - $extraLength[1] < 8) {
1403
-                return PEAR::raiseError('_decodeGzip(): data too short');
1404
-            }
1405
-            $headerLength += $extraLength[1] + 2;
1406
-        }
1407
-        // file name, need to skip that
1408
-        if ($flags & 8) {
1409
-            if ($length - $headerLength - 1 < 8) {
1410
-                return PEAR::raiseError('_decodeGzip(): data too short');
1411
-            }
1412
-            $filenameLength = strpos(substr($data, $headerLength), chr(0));
1413
-            if (false === $filenameLength || $length - $headerLength - $filenameLength - 1 < 8) {
1414
-                return PEAR::raiseError('_decodeGzip(): data too short');
1415
-            }
1416
-            $headerLength += $filenameLength + 1;
1417
-        }
1418
-        // comment, need to skip that also
1419
-        if ($flags & 16) {
1420
-            if ($length - $headerLength - 1 < 8) {
1421
-                return PEAR::raiseError('_decodeGzip(): data too short');
1422
-            }
1423
-            $commentLength = strpos(substr($data, $headerLength), chr(0));
1424
-            if (false === $commentLength || $length - $headerLength - $commentLength - 1 < 8) {
1425
-                return PEAR::raiseError('_decodeGzip(): data too short');
1426
-            }
1427
-            $headerLength += $commentLength + 1;
1428
-        }
1429
-        // have a CRC for header. let's check
1430
-        if ($flags & 1) {
1431
-            if ($length - $headerLength - 2 < 8) {
1432
-                return PEAR::raiseError('_decodeGzip(): data too short');
1433
-            }
1434
-            $crcReal   = 0xffff & crc32(substr($data, 0, $headerLength));
1435
-            $crcStored = unpack('v', substr($data, $headerLength, 2));
1436
-            if ($crcReal != $crcStored[1]) {
1437
-                return PEAR::raiseError('_decodeGzip(): header CRC check failed');
1438
-            }
1439
-            $headerLength += 2;
1440
-        }
1441
-        // unpacked data CRC and size at the end of encoded data
1442
-        $tmp = unpack('V2', substr($data, -8));
1443
-        $dataCrc  = $tmp[1];
1444
-        $dataSize = $tmp[2];
1445
-
1446
-        // finally, call the gzinflate() function
1447
-        $unpacked = @gzinflate(substr($data, $headerLength, -8), $dataSize);
1448
-        if (false === $unpacked) {
1449
-            return PEAR::raiseError('_decodeGzip(): gzinflate() call failed');
1450
-        } elseif ($dataSize != strlen($unpacked)) {
1451
-            return PEAR::raiseError('_decodeGzip(): data size check failed');
1452
-        } elseif ((0xffffffff & $dataCrc) != (0xffffffff & crc32($unpacked))) {
1453
-            return PEAR::raiseError('_decodeGzip(): data CRC check failed');
1454
-        }
1455
-        if (HTTP_REQUEST_MBSTRING) {
1456
-            mb_internal_encoding($oldEncoding);
1457
-        }
1458
-        return $unpacked;
1459
-    }
1374
+	function _decodeGzip($data)
1375
+	{
1376
+		if (HTTP_REQUEST_MBSTRING) {
1377
+			$oldEncoding = mb_internal_encoding();
1378
+			mb_internal_encoding('iso-8859-1');
1379
+		}
1380
+		$length = strlen($data);
1381
+		// If it doesn't look like gzip-encoded data, don't bother
1382
+		if (18 > $length || strcmp(substr($data, 0, 2), "\x1f\x8b")) {
1383
+			return $data;
1384
+		}
1385
+		$method = ord(substr($data, 2, 1));
1386
+		if (8 != $method) {
1387
+			return PEAR::raiseError('_decodeGzip(): unknown compression method');
1388
+		}
1389
+		$flags = ord(substr($data, 3, 1));
1390
+		if ($flags & 224) {
1391
+			return PEAR::raiseError('_decodeGzip(): reserved bits are set');
1392
+		}
1393
+
1394
+		// header is 10 bytes minimum. may be longer, though.
1395
+		$headerLength = 10;
1396
+		// extra fields, need to skip 'em
1397
+		if ($flags & 4) {
1398
+			if ($length - $headerLength - 2 < 8) {
1399
+				return PEAR::raiseError('_decodeGzip(): data too short');
1400
+			}
1401
+			$extraLength = unpack('v', substr($data, 10, 2));
1402
+			if ($length - $headerLength - 2 - $extraLength[1] < 8) {
1403
+				return PEAR::raiseError('_decodeGzip(): data too short');
1404
+			}
1405
+			$headerLength += $extraLength[1] + 2;
1406
+		}
1407
+		// file name, need to skip that
1408
+		if ($flags & 8) {
1409
+			if ($length - $headerLength - 1 < 8) {
1410
+				return PEAR::raiseError('_decodeGzip(): data too short');
1411
+			}
1412
+			$filenameLength = strpos(substr($data, $headerLength), chr(0));
1413
+			if (false === $filenameLength || $length - $headerLength - $filenameLength - 1 < 8) {
1414
+				return PEAR::raiseError('_decodeGzip(): data too short');
1415
+			}
1416
+			$headerLength += $filenameLength + 1;
1417
+		}
1418
+		// comment, need to skip that also
1419
+		if ($flags & 16) {
1420
+			if ($length - $headerLength - 1 < 8) {
1421
+				return PEAR::raiseError('_decodeGzip(): data too short');
1422
+			}
1423
+			$commentLength = strpos(substr($data, $headerLength), chr(0));
1424
+			if (false === $commentLength || $length - $headerLength - $commentLength - 1 < 8) {
1425
+				return PEAR::raiseError('_decodeGzip(): data too short');
1426
+			}
1427
+			$headerLength += $commentLength + 1;
1428
+		}
1429
+		// have a CRC for header. let's check
1430
+		if ($flags & 1) {
1431
+			if ($length - $headerLength - 2 < 8) {
1432
+				return PEAR::raiseError('_decodeGzip(): data too short');
1433
+			}
1434
+			$crcReal   = 0xffff & crc32(substr($data, 0, $headerLength));
1435
+			$crcStored = unpack('v', substr($data, $headerLength, 2));
1436
+			if ($crcReal != $crcStored[1]) {
1437
+				return PEAR::raiseError('_decodeGzip(): header CRC check failed');
1438
+			}
1439
+			$headerLength += 2;
1440
+		}
1441
+		// unpacked data CRC and size at the end of encoded data
1442
+		$tmp = unpack('V2', substr($data, -8));
1443
+		$dataCrc  = $tmp[1];
1444
+		$dataSize = $tmp[2];
1445
+
1446
+		// finally, call the gzinflate() function
1447
+		$unpacked = @gzinflate(substr($data, $headerLength, -8), $dataSize);
1448
+		if (false === $unpacked) {
1449
+			return PEAR::raiseError('_decodeGzip(): gzinflate() call failed');
1450
+		} elseif ($dataSize != strlen($unpacked)) {
1451
+			return PEAR::raiseError('_decodeGzip(): data size check failed');
1452
+		} elseif ((0xffffffff & $dataCrc) != (0xffffffff & crc32($unpacked))) {
1453
+			return PEAR::raiseError('_decodeGzip(): data CRC check failed');
1454
+		}
1455
+		if (HTTP_REQUEST_MBSTRING) {
1456
+			mb_internal_encoding($oldEncoding);
1457
+		}
1458
+		return $unpacked;
1459
+	}
1460 1460
 } // End class HTTP_Response
1461 1461
 ?>
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -60,13 +60,13 @@  discard block
 block discarded – undo
60 60
 /**#@+
61 61
  * Constants for HTTP request methods
62 62
  */ 
63
-define('HTTP_REQUEST_METHOD_GET',     'GET',     true);
64
-define('HTTP_REQUEST_METHOD_HEAD',    'HEAD',    true);
65
-define('HTTP_REQUEST_METHOD_POST',    'POST',    true);
66
-define('HTTP_REQUEST_METHOD_PUT',     'PUT',     true);
67
-define('HTTP_REQUEST_METHOD_DELETE',  'DELETE',  true);
63
+define('HTTP_REQUEST_METHOD_GET', 'GET', true);
64
+define('HTTP_REQUEST_METHOD_HEAD', 'HEAD', true);
65
+define('HTTP_REQUEST_METHOD_POST', 'POST', true);
66
+define('HTTP_REQUEST_METHOD_PUT', 'PUT', true);
67
+define('HTTP_REQUEST_METHOD_DELETE', 'DELETE', true);
68 68
 define('HTTP_REQUEST_METHOD_OPTIONS', 'OPTIONS', true);
69
-define('HTTP_REQUEST_METHOD_TRACE',   'TRACE',   true);
69
+define('HTTP_REQUEST_METHOD_TRACE', 'TRACE', true);
70 70
 /**#@-*/
71 71
 
72 72
 /**#@+
@@ -287,8 +287,8 @@  discard block
 block discarded – undo
287 287
     */
288 288
     function HTTP_Request($url = '', $params = array())
289 289
     {
290
-        $this->_method         =  HTTP_REQUEST_METHOD_GET;
291
-        $this->_http           =  HTTP_REQUEST_HTTP_VER_1_1;
290
+        $this->_method         = HTTP_REQUEST_METHOD_GET;
291
+        $this->_http           = HTTP_REQUEST_HTTP_VER_1_1;
292 292
         $this->_requestHeaders = array();
293 293
         $this->_postData       = array();
294 294
         $this->_body           = null;
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
         $this->_response = null;
310 310
 
311 311
         foreach ($params as $key => $value) {
312
-            $this->{'_' . $key} = $value;
312
+            $this->{'_'.$key} = $value;
313 313
         }
314 314
 
315 315
         if (!empty($url)) {
@@ -324,12 +324,12 @@  discard block
 block discarded – undo
324 324
 
325 325
         // Basic authentication
326 326
         if (!empty($this->_user)) {
327
-            $this->addHeader('Authorization', 'Basic ' . base64_encode($this->_user . ':' . $this->_pass));
327
+            $this->addHeader('Authorization', 'Basic '.base64_encode($this->_user.':'.$this->_pass));
328 328
         }
329 329
 
330 330
         // Proxy authentication (see bug #5913)
331 331
         if (!empty($this->_proxy_user)) {
332
-            $this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($this->_proxy_user . ':' . $this->_proxy_pass));
332
+            $this->addHeader('Proxy-Authorization', 'Basic '.base64_encode($this->_proxy_user.':'.$this->_proxy_pass));
333 333
         }
334 334
 
335 335
         // Use gzip encoding if possible
@@ -347,13 +347,13 @@  discard block
 block discarded – undo
347 347
     function _generateHostHeader()
348 348
     {
349 349
         if ($this->_url->port != 80 AND strcasecmp($this->_url->protocol, 'http') == 0) {
350
-            $host = $this->_url->host . ':' . $this->_url->port;
350
+            $host = $this->_url->host.':'.$this->_url->port;
351 351
 
352 352
         } elseif ($this->_url->port != 443 AND strcasecmp($this->_url->protocol, 'https') == 0) {
353
-            $host = $this->_url->host . ':' . $this->_url->port;
353
+            $host = $this->_url->host.':'.$this->_url->port;
354 354
 
355 355
         } elseif ($this->_url->port == 443 AND strcasecmp($this->_url->protocol, 'https') == 0 AND strpos($this->_url->url, ':443') !== false) {
356
-            $host = $this->_url->host . ':' . $this->_url->port;
356
+            $host = $this->_url->host.':'.$this->_url->port;
357 357
         
358 358
         } else {
359 359
             $host = $this->_url->host;
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
     */
410 410
     function getUrl()
411 411
     {
412
-        return empty($this->_url)? '': $this->_url->getUrl();
412
+        return empty($this->_url) ? '' : $this->_url->getUrl();
413 413
     }
414 414
 
415 415
     /**
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
         $this->_proxy_pass = $pass;
430 430
 
431 431
         if (!empty($user)) {
432
-            $this->addHeader('Proxy-Authorization', 'Basic ' . base64_encode($user . ':' . $pass));
432
+            $this->addHeader('Proxy-Authorization', 'Basic '.base64_encode($user.':'.$pass));
433 433
         }
434 434
     }
435 435
 
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
         $this->_user = $user;
445 445
         $this->_pass = $pass;
446 446
 
447
-        $this->addHeader('Authorization', 'Basic ' . base64_encode($user . ':' . $pass));
447
+        $this->addHeader('Authorization', 'Basic '.base64_encode($user.':'.$pass));
448 448
     }
449 449
 
450 450
     /**
@@ -634,8 +634,8 @@  discard block
 block discarded – undo
634 634
     */
635 635
     function addCookie($name, $value)
636 636
     {
637
-        $cookies = isset($this->_requestHeaders['cookie']) ? $this->_requestHeaders['cookie']. '; ' : '';
638
-        $this->addHeader('Cookie', $cookies . $name . '=' . $value);
637
+        $cookies = isset($this->_requestHeaders['cookie']) ? $this->_requestHeaders['cookie'].'; ' : '';
638
+        $this->addHeader('Cookie', $cookies.$name.'='.$value);
639 639
     }
640 640
     
641 641
     /**
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
             if (isset($this->_proxy_host)) {
675 675
                 return PEAR::raiseError('HTTPS proxies are not supported.');
676 676
             }
677
-            $host = 'ssl://' . $host;
677
+            $host = 'ssl://'.$host;
678 678
         }
679 679
 
680 680
         // magic quotes may fuck up file uploads and chunked response processing
@@ -692,18 +692,18 @@  discard block
 block discarded – undo
692 692
         $keepAlive = (HTTP_REQUEST_HTTP_VER_1_1 == $this->_http && empty($this->_requestHeaders['connection'])) ||
693 693
                      (!empty($this->_requestHeaders['connection']) && 'Keep-Alive' == $this->_requestHeaders['connection']);
694 694
         $sockets   = &PEAR::getStaticProperty('HTTP_Request', 'sockets');
695
-        $sockKey   = $host . ':' . $port;
695
+        $sockKey   = $host.':'.$port;
696 696
         unset($this->_sock);
697 697
 
698 698
         // There is a connected socket in the "static" property?
699 699
         if ($keepAlive && !empty($sockets[$sockKey]) &&
700 700
             !empty($sockets[$sockKey]->fp)) 
701 701
         {
702
-            $this->_sock =& $sockets[$sockKey];
702
+            $this->_sock = & $sockets[$sockKey];
703 703
             $err = null;
704 704
         } else {
705 705
             $this->_notify('connect');
706
-            $this->_sock =& new Net_Socket();
706
+            $this->_sock = & new Net_Socket();
707 707
             $err = $this->_sock->connect($host, $port, null, $this->_timeout, $this->_socketOptions);
708 708
         }
709 709
         PEAR::isError($err) or $err = $this->_sock->write($this->_buildRequest());
@@ -746,11 +746,11 @@  discard block
 block discarded – undo
746 746
             $this->disconnect();
747 747
         // Store the connected socket in "static" property
748 748
         } elseif (empty($sockets[$sockKey]) || empty($sockets[$sockKey]->fp)) {
749
-            $sockets[$sockKey] =& $this->_sock;
749
+            $sockets[$sockKey] = & $this->_sock;
750 750
         }
751 751
 
752 752
         // Check for redirection
753
-        if (    $this->_allowRedirects
753
+        if ($this->_allowRedirects
754 754
             AND $this->_redirects <= $this->_maxRedirects
755 755
             AND $this->getResponseCode() > 300
756 756
             AND $this->getResponseCode() < 399
@@ -770,9 +770,9 @@  discard block
 block discarded – undo
770 770
             // Relative path
771 771
             } elseif (substr($redirect, 0, 3) == '../' OR substr($redirect, 0, 2) == './') {
772 772
                 if (substr($this->_url->path, -1) == '/') {
773
-                    $redirect = $this->_url->path . $redirect;
773
+                    $redirect = $this->_url->path.$redirect;
774 774
                 } else {
775
-                    $redirect = dirname($this->_url->path) . '/' . $redirect;
775
+                    $redirect = dirname($this->_url->path).'/'.$redirect;
776 776
                 }
777 777
                 $redirect = Net_URL::resolvePath($redirect);
778 778
                 $this->_url->path = $redirect;
@@ -780,9 +780,9 @@  discard block
 block discarded – undo
780 780
             // Filename, no path
781 781
             } else {
782 782
                 if (substr($this->_url->path, -1) == '/') {
783
-                    $redirect = $this->_url->path . $redirect;
783
+                    $redirect = $this->_url->path.$redirect;
784 784
                 } else {
785
-                    $redirect = dirname($this->_url->path) . '/' . $redirect;
785
+                    $redirect = dirname($this->_url->path).'/'.$redirect;
786 786
                 }
787 787
                 $this->_url->path = $redirect;
788 788
             }
@@ -833,7 +833,7 @@  discard block
 block discarded – undo
833 833
     function getResponseHeader($headername = null)
834 834
     {
835 835
         if (!isset($headername)) {
836
-            return isset($this->_response->_headers)? $this->_response->_headers: array();
836
+            return isset($this->_response->_headers) ? $this->_response->_headers : array();
837 837
         } else {
838 838
             $headername = strtolower($headername);
839 839
             return isset($this->_response->_headers[$headername]) ? $this->_response->_headers[$headername] : false;
@@ -872,15 +872,15 @@  discard block
 block discarded – undo
872 872
     {
873 873
         $separator = ini_get('arg_separator.output');
874 874
         ini_set('arg_separator.output', '&');
875
-        $querystring = ($querystring = $this->_url->getQueryString()) ? '?' . $querystring : '';
875
+        $querystring = ($querystring = $this->_url->getQueryString()) ? '?'.$querystring : '';
876 876
         ini_set('arg_separator.output', $separator);
877 877
 
878
-        $host = isset($this->_proxy_host) ? $this->_url->protocol . '://' . $this->_url->host : '';
879
-        $port = (isset($this->_proxy_host) AND $this->_url->port != 80) ? ':' . $this->_url->port : '';
880
-        $path = $this->_url->path . $querystring;
881
-        $url  = $host . $port . $path;
878
+        $host = isset($this->_proxy_host) ? $this->_url->protocol.'://'.$this->_url->host : '';
879
+        $port = (isset($this->_proxy_host) AND $this->_url->port != 80) ? ':'.$this->_url->port : '';
880
+        $path = $this->_url->path.$querystring;
881
+        $url  = $host.$port.$path;
882 882
 
883
-        $request = $this->_method . ' ' . $url . ' HTTP/' . $this->_http . "\r\n";
883
+        $request = $this->_method.' '.$url.' HTTP/'.$this->_http."\r\n";
884 884
 
885 885
         if (in_array($this->_method, $this->_bodyDisallowed) ||
886 886
             (empty($this->_body) && (HTTP_REQUEST_METHOD_POST != $this->_method ||
@@ -892,8 +892,8 @@  discard block
 block discarded – undo
892 892
                 // Add default content-type
893 893
                 $this->addHeader('Content-Type', 'application/x-www-form-urlencoded');
894 894
             } elseif ('multipart/form-data' == $this->_requestHeaders['content-type']) {
895
-                $boundary = 'HTTP_Request_' . md5(uniqid('request') . microtime());
896
-                $this->addHeader('Content-Type', 'multipart/form-data; boundary=' . $boundary);
895
+                $boundary = 'HTTP_Request_'.md5(uniqid('request').microtime());
896
+                $this->addHeader('Content-Type', 'multipart/form-data; boundary='.$boundary);
897 897
             }
898 898
         }
899 899
 
@@ -901,7 +901,7 @@  discard block
 block discarded – undo
901 901
         if (!empty($this->_requestHeaders)) {
902 902
             foreach ($this->_requestHeaders as $name => $value) {
903 903
                 $canonicalName = implode('-', array_map('ucfirst', explode('-', $name)));
904
-                $request      .= $canonicalName . ': ' . $value . "\r\n";
904
+                $request      .= $canonicalName.': '.$value."\r\n";
905 905
             }
906 906
         }
907 907
 
@@ -928,14 +928,14 @@  discard block
 block discarded – undo
928 928
                 if (!empty($this->_postData)) {
929 929
                     $flatData = $this->_flattenArray('', $this->_postData);
930 930
                     foreach ($flatData as $item) {
931
-                        $postdata .= '--' . $boundary . "\r\n";
932
-                        $postdata .= 'Content-Disposition: form-data; name="' . $item[0] . '"';
933
-                        $postdata .= "\r\n\r\n" . urldecode($item[1]) . "\r\n";
931
+                        $postdata .= '--'.$boundary."\r\n";
932
+                        $postdata .= 'Content-Disposition: form-data; name="'.$item[0].'"';
933
+                        $postdata .= "\r\n\r\n".urldecode($item[1])."\r\n";
934 934
                     }
935 935
                 }
936 936
                 foreach ($this->_postFiles as $name => $value) {
937 937
                     if (is_array($value['name'])) {
938
-                        $varname       = $name . ($this->_useBrackets? '[]': '');
938
+                        $varname       = $name.($this->_useBrackets ? '[]' : '');
939 939
                     } else {
940 940
                         $varname       = $name;
941 941
                         $value['name'] = array($value['name']);
@@ -945,26 +945,26 @@  discard block
 block discarded – undo
945 945
                         $data = fread($fp, filesize($filename));
946 946
                         fclose($fp);
947 947
                         $basename = basename($filename);
948
-                        $type     = is_array($value['type'])? @$value['type'][$key]: $value['type'];
948
+                        $type     = is_array($value['type']) ? @$value['type'][$key] : $value['type'];
949 949
 
950
-                        $postdata .= '--' . $boundary . "\r\n";
951
-                        $postdata .= 'Content-Disposition: form-data; name="' . $varname . '"; filename="' . $basename . '"';
952
-                        $postdata .= "\r\nContent-Type: " . $type;
953
-                        $postdata .= "\r\n\r\n" . $data . "\r\n";
950
+                        $postdata .= '--'.$boundary."\r\n";
951
+                        $postdata .= 'Content-Disposition: form-data; name="'.$varname.'"; filename="'.$basename.'"';
952
+                        $postdata .= "\r\nContent-Type: ".$type;
953
+                        $postdata .= "\r\n\r\n".$data."\r\n";
954 954
                     }
955 955
                 }
956
-                $postdata .= '--' . $boundary . "--\r\n";
956
+                $postdata .= '--'.$boundary."--\r\n";
957 957
             }
958
-            $request .= 'Content-Length: ' .
959
-                        (HTTP_REQUEST_MBSTRING? mb_strlen($postdata, 'iso-8859-1'): strlen($postdata)) .
958
+            $request .= 'Content-Length: '.
959
+                        (HTTP_REQUEST_MBSTRING ? mb_strlen($postdata, 'iso-8859-1') : strlen($postdata)).
960 960
                         "\r\n\r\n";
961 961
             $request .= $postdata;
962 962
 
963 963
         // Explicitly set request body
964 964
         } elseif (!empty($this->_body)) {
965 965
 
966
-            $request .= 'Content-Length: ' .
967
-                        (HTTP_REQUEST_MBSTRING? mb_strlen($this->_body, 'iso-8859-1'): strlen($this->_body)) .
966
+            $request .= 'Content-Length: '.
967
+                        (HTTP_REQUEST_MBSTRING ? mb_strlen($this->_body, 'iso-8859-1') : strlen($this->_body)).
968 968
                         "\r\n\r\n";
969 969
             $request .= $this->_body;
970 970
         }
@@ -991,7 +991,7 @@  discard block
 block discarded – undo
991 991
                 if (empty($name)) {
992 992
                     $newName = $k;
993 993
                 } elseif ($this->_useBrackets) {
994
-                    $newName = $name . '[' . $k . ']';
994
+                    $newName = $name.'['.$k.']';
995 995
                 } else {
996 996
                     $newName = $name;
997 997
                 }
@@ -1026,7 +1026,7 @@  discard block
 block discarded – undo
1026 1026
         if (!is_a($listener, 'HTTP_Request_Listener')) {
1027 1027
             return false;
1028 1028
         }
1029
-        $this->_listeners[$listener->getId()] =& $listener;
1029
+        $this->_listeners[$listener->getId()] = & $listener;
1030 1030
         return true;
1031 1031
     }
1032 1032
 
@@ -1139,8 +1139,8 @@  discard block
 block discarded – undo
1139 1139
     */
1140 1140
     function HTTP_Response(&$sock, &$listeners)
1141 1141
     {
1142
-        $this->_sock      =& $sock;
1143
-        $this->_listeners =& $listeners;
1142
+        $this->_sock      = & $sock;
1143
+        $this->_listeners = & $listeners;
1144 1144
     }
1145 1145
 
1146 1146
 
@@ -1166,7 +1166,7 @@  discard block
 block discarded – undo
1166 1166
             if (sscanf($line, 'HTTP/%s %s', $http_version, $returncode) != 2) {
1167 1167
                 return PEAR::raiseError('Malformed response.');
1168 1168
             } else {
1169
-                $this->_protocol = 'HTTP/' . $http_version;
1169
+                $this->_protocol = 'HTTP/'.$http_version;
1170 1170
                 $this->_code     = intval($returncode);
1171 1171
             }
1172 1172
             while ('' !== ($header = $this->_sock->readLine())) {
@@ -1204,7 +1204,7 @@  discard block
 block discarded – undo
1204 1204
                     $data = $this->_sock->read(4096);
1205 1205
                 } else {
1206 1206
                     $data = $this->_sock->read(min(4096, $this->_toRead));
1207
-                    $this->_toRead -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data);
1207
+                    $this->_toRead -= HTTP_REQUEST_MBSTRING ? mb_strlen($data, 'iso-8859-1') : strlen($data);
1208 1208
                 }
1209 1209
                 if ('' == $data) {
1210 1210
                     break;
@@ -1213,7 +1213,7 @@  discard block
 block discarded – undo
1213 1213
                     if ($saveBody || $gzipped) {
1214 1214
                         $this->_body .= $data;
1215 1215
                     }
1216
-                    $this->_notify($gzipped? 'gzTick': 'tick', $data);
1216
+                    $this->_notify($gzipped ? 'gzTick' : 'tick', $data);
1217 1217
                 }
1218 1218
             }
1219 1219
         }
@@ -1252,7 +1252,7 @@  discard block
 block discarded – undo
1252 1252
         
1253 1253
         if ('set-cookie' != $headername) {
1254 1254
             if (isset($this->_headers[$headername])) {
1255
-                $this->_headers[$headername] .= ',' . $headervalue;
1255
+                $this->_headers[$headername] .= ','.$headervalue;
1256 1256
             } else {
1257 1257
                 $this->_headers[$headername]  = $headervalue;
1258 1258
             }
@@ -1336,7 +1336,7 @@  discard block
 block discarded – undo
1336 1336
             }
1337 1337
         }
1338 1338
         $data = $this->_sock->read($this->_chunkLength);
1339
-        $this->_chunkLength -= HTTP_REQUEST_MBSTRING? mb_strlen($data, 'iso-8859-1'): strlen($data);
1339
+        $this->_chunkLength -= HTTP_REQUEST_MBSTRING ? mb_strlen($data, 'iso-8859-1') : strlen($data);
1340 1340
         if (0 == $this->_chunkLength) {
1341 1341
             $this->_sock->readLine(); // Trailing CRLF
1342 1342
         }
Please login to merge, or discard this patch.
libs/PEAR/Net/URL.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -340,7 +340,7 @@
 block discarded – undo
340 340
     *
341 341
     * This method can also be called statically.
342 342
     *
343
-    * @param  string $url URL path to resolve
343
+    * @param string $path
344 344
     * @return string      The result
345 345
     */
346 346
     function resolvePath($path)
Please login to merge, or discard this patch.
Indentation   +367 added lines, -367 removed lines patch added patch discarded remove patch
@@ -38,373 +38,373 @@
 block discarded – undo
38 38
 
39 39
 class Net_URL
40 40
 {
41
-    /**
42
-    * Full url
43
-    * @var string
44
-    */
45
-    var $url;
46
-
47
-    /**
48
-    * Protocol
49
-    * @var string
50
-    */
51
-    var $protocol;
52
-
53
-    /**
54
-    * Username
55
-    * @var string
56
-    */
57
-    var $username;
58
-
59
-    /**
60
-    * Password
61
-    * @var string
62
-    */
63
-    var $password;
64
-
65
-    /**
66
-    * Host
67
-    * @var string
68
-    */
69
-    var $host;
70
-
71
-    /**
72
-    * Port
73
-    * @var integer
74
-    */
75
-    var $port;
76
-
77
-    /**
78
-    * Path
79
-    * @var string
80
-    */
81
-    var $path;
82
-
83
-    /**
84
-    * Query string
85
-    * @var array
86
-    */
87
-    var $querystring;
88
-
89
-    /**
90
-    * Anchor
91
-    * @var string
92
-    */
93
-    var $anchor;
94
-
95
-    /**
96
-    * Whether to use []
97
-    * @var bool
98
-    */
99
-    var $useBrackets;
100
-
101
-    /**
102
-    * PHP4 Constructor
103
-    *
104
-    * @see __construct()
105
-    */
106
-    function Net_URL($url = null, $useBrackets = true)
107
-    {
108
-        $this->__construct($url, $useBrackets);
109
-    }
110
-
111
-    /**
112
-    * PHP5 Constructor
113
-    *
114
-    * Parses the given url and stores the various parts
115
-    * Defaults are used in certain cases
116
-    *
117
-    * @param string $url         Optional URL
118
-    * @param bool   $useBrackets Whether to use square brackets when
119
-    *                            multiple querystrings with the same name
120
-    *                            exist
121
-    */
122
-    function __construct($url = null, $useBrackets = true)
123
-    {
124
-        $HTTP_SERVER_VARS  = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
125
-
126
-        $this->useBrackets = $useBrackets;
127
-        $this->url         = $url;
128
-        $this->user        = '';
129
-        $this->pass        = '';
130
-        $this->host        = '';
131
-        $this->port        = 80;
132
-        $this->path        = '';
133
-        $this->querystring = array();
134
-        $this->anchor      = '';
135
-
136
-        // Only use defaults if not an absolute URL given
137
-        if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) {
138
-
139
-            $this->protocol    = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http');
140
-
141
-            /**
142
-            * Figure out host/port
143
-            */
144
-            if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) {
145
-                $host = $matches[1];
146
-                if (!empty($matches[3])) {
147
-                    $port = $matches[3];
148
-                } else {
149
-                    $port = $this->getStandardPort($this->protocol);
150
-                }
151
-            }
152
-
153
-            $this->user        = '';
154
-            $this->pass        = '';
155
-            $this->host        = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');
156
-            $this->port        = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol));
157
-            $this->path        = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';
158
-            $this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;
159
-            $this->anchor      = '';
160
-        }
161
-
162
-        // Parse the url and store the various parts
163
-        if (!empty($url)) {
164
-            $urlinfo = parse_url($url);
165
-
166
-            // Default querystring
167
-            $this->querystring = array();
168
-
169
-            foreach ($urlinfo as $key => $value) {
170
-                switch ($key) {
171
-                    case 'scheme':
172
-                        $this->protocol = $value;
173
-                        $this->port     = $this->getStandardPort($value);
174
-                        break;
175
-
176
-                    case 'user':
177
-                    case 'pass':
178
-                    case 'host':
179
-                    case 'port':
180
-                        $this->$key = $value;
181
-                        break;
182
-
183
-                    case 'path':
184
-                        if ($value{0} == '/') {
185
-                            $this->path = $value;
186
-                        } else {
187
-                            $path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);
188
-                            $this->path = sprintf('%s/%s', $path, $value);
189
-                        }
190
-                        break;
191
-
192
-                    case 'query':
193
-                        $this->querystring = $this->_parseRawQueryString($value);
194
-                        break;
195
-
196
-                    case 'fragment':
197
-                        $this->anchor = $value;
198
-                        break;
199
-                }
200
-            }
201
-        }
202
-    }
203
-
204
-    /**
205
-    * Returns full url
206
-    *
207
-    * @return string Full url
208
-    * @access public
209
-    */
210
-    function getURL()
211
-    {
212
-        $querystring = $this->getQueryString();
213
-
214
-        $this->url = $this->protocol . '://'
215
-                   . $this->user . (!empty($this->pass) ? ':' : '')
216
-                   . $this->pass . (!empty($this->user) ? '@' : '')
217
-                   . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)
218
-                   . $this->path
219
-                   . (!empty($querystring) ? '?' . $querystring : '')
220
-                   . (!empty($this->anchor) ? '#' . $this->anchor : '');
221
-
222
-        return $this->url;
223
-    }
224
-
225
-    /**
226
-    * Adds a querystring item
227
-    *
228
-    * @param  string $name       Name of item
229
-    * @param  string $value      Value of item
230
-    * @param  bool   $preencoded Whether value is urlencoded or not, default = not
231
-    * @access public
232
-    */
233
-    function addQueryString($name, $value, $preencoded = false)
234
-    {
235
-        if ($preencoded) {
236
-            $this->querystring[$name] = $value;
237
-        } else {
238
-            $this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value);
239
-        }
240
-    }
241
-
242
-    /**
243
-    * Removes a querystring item
244
-    *
245
-    * @param  string $name Name of item
246
-    * @access public
247
-    */
248
-    function removeQueryString($name)
249
-    {
250
-        if (isset($this->querystring[$name])) {
251
-            unset($this->querystring[$name]);
252
-        }
253
-    }
254
-
255
-    /**
256
-    * Sets the querystring to literally what you supply
257
-    *
258
-    * @param  string $querystring The querystring data. Should be of the format foo=bar&x=y etc
259
-    * @access public
260
-    */
261
-    function addRawQueryString($querystring)
262
-    {
263
-        $this->querystring = $this->_parseRawQueryString($querystring);
264
-    }
265
-
266
-    /**
267
-    * Returns flat querystring
268
-    *
269
-    * @return string Querystring
270
-    * @access public
271
-    */
272
-    function getQueryString()
273
-    {
274
-        if (!empty($this->querystring)) {
275
-            foreach ($this->querystring as $name => $value) {
276
-                if (is_array($value)) {
277
-                    foreach ($value as $k => $v) {
278
-                        $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v);
279
-                    }
280
-                } elseif (!is_null($value)) {
281
-                    $querystring[] = $name . '=' . $value;
282
-                } else {
283
-                    $querystring[] = $name;
284
-                }
285
-            }
286
-            $querystring = implode(ini_get('arg_separator.output'), $querystring);
287
-        } else {
288
-            $querystring = '';
289
-        }
290
-
291
-        return $querystring;
292
-    }
293
-
294
-    /**
295
-    * Parses raw querystring and returns an array of it
296
-    *
297
-    * @param  string  $querystring The querystring to parse
298
-    * @return array                An array of the querystring data
299
-    * @access private
300
-    */
301
-    function _parseRawQuerystring($querystring)
302
-    {
303
-        $parts  = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);
304
-        $return = array();
305
-
306
-        foreach ($parts as $part) {
307
-            if (strpos($part, '=') !== false) {
308
-                $value = substr($part, strpos($part, '=') + 1);
309
-                $key   = substr($part, 0, strpos($part, '='));
310
-            } else {
311
-                $value = null;
312
-                $key   = $part;
313
-            }
314
-            if (substr($key, -2) == '[]') {
315
-                $key = substr($key, 0, -2);
316
-                if (@!is_array($return[$key])) {
317
-                    $return[$key]   = array();
318
-                    $return[$key][] = $value;
319
-                } else {
320
-                    $return[$key][] = $value;
321
-                }
322
-            } elseif (!$this->useBrackets AND !empty($return[$key])) {
323
-                $return[$key]   = (array)$return[$key];
324
-                $return[$key][] = $value;
325
-            } else {
326
-                $return[$key] = $value;
327
-            }
328
-        }
329
-
330
-        return $return;
331
-    }
332
-
333
-    /**
334
-    * Resolves //, ../ and ./ from a path and returns
335
-    * the result. Eg:
336
-    *
337
-    * /foo/bar/../boo.php    => /foo/boo.php
338
-    * /foo/bar/../../boo.php => /boo.php
339
-    * /foo/bar/.././/boo.php => /foo/boo.php
340
-    *
341
-    * This method can also be called statically.
342
-    *
343
-    * @param  string $url URL path to resolve
344
-    * @return string      The result
345
-    */
346
-    function resolvePath($path)
347
-    {
348
-        $path = explode('/', str_replace('//', '/', $path));
349
-
350
-        for ($i=0; $i<count($path); $i++) {
351
-            if ($path[$i] == '.') {
352
-                unset($path[$i]);
353
-                $path = array_values($path);
354
-                $i--;
355
-
356
-            } elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {
357
-                unset($path[$i]);
358
-                unset($path[$i-1]);
359
-                $path = array_values($path);
360
-                $i -= 2;
361
-
362
-            } elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') {
363
-                unset($path[$i]);
364
-                $path = array_values($path);
365
-                $i--;
366
-
367
-            } else {
368
-                continue;
369
-            }
370
-        }
371
-
372
-        return implode('/', $path);
373
-    }
374
-
375
-    /**
376
-    * Returns the standard port number for a protocol
377
-    *
378
-    * @param  string  $scheme The protocol to lookup
379
-    * @return integer         Port number or NULL if no scheme matches
380
-    *
381
-    * @author Philippe Jausions <[email protected]>
382
-    */
383
-    function getStandardPort($scheme)
384
-    {
385
-        switch (strtolower($scheme)) {
386
-            case 'http':    return 80;
387
-            case 'https':   return 443;
388
-            case 'ftp':     return 21;
389
-            case 'imap':    return 143;
390
-            case 'imaps':   return 993;
391
-            case 'pop3':    return 110;
392
-            case 'pop3s':   return 995;
393
-            default:        return null;
394
-       }
395
-    }
396
-
397
-    /**
398
-    * Forces the URL to a particular protocol
399
-    *
400
-    * @param string  $protocol Protocol to force the URL to
401
-    * @param integer $port     Optional port (standard port is used by default)
402
-    */
403
-    function setProtocol($protocol, $port = null)
404
-    {
405
-        $this->protocol = $protocol;
406
-        $this->port = is_null($port) ? $this->getStandardPort() : $port;
407
-    }
41
+	/**
42
+	 * Full url
43
+	 * @var string
44
+	 */
45
+	var $url;
46
+
47
+	/**
48
+	 * Protocol
49
+	 * @var string
50
+	 */
51
+	var $protocol;
52
+
53
+	/**
54
+	 * Username
55
+	 * @var string
56
+	 */
57
+	var $username;
58
+
59
+	/**
60
+	 * Password
61
+	 * @var string
62
+	 */
63
+	var $password;
64
+
65
+	/**
66
+	 * Host
67
+	 * @var string
68
+	 */
69
+	var $host;
70
+
71
+	/**
72
+	 * Port
73
+	 * @var integer
74
+	 */
75
+	var $port;
76
+
77
+	/**
78
+	 * Path
79
+	 * @var string
80
+	 */
81
+	var $path;
82
+
83
+	/**
84
+	 * Query string
85
+	 * @var array
86
+	 */
87
+	var $querystring;
88
+
89
+	/**
90
+	 * Anchor
91
+	 * @var string
92
+	 */
93
+	var $anchor;
94
+
95
+	/**
96
+	 * Whether to use []
97
+	 * @var bool
98
+	 */
99
+	var $useBrackets;
100
+
101
+	/**
102
+	 * PHP4 Constructor
103
+	 *
104
+	 * @see __construct()
105
+	 */
106
+	function Net_URL($url = null, $useBrackets = true)
107
+	{
108
+		$this->__construct($url, $useBrackets);
109
+	}
110
+
111
+	/**
112
+	 * PHP5 Constructor
113
+	 *
114
+	 * Parses the given url and stores the various parts
115
+	 * Defaults are used in certain cases
116
+	 *
117
+	 * @param string $url         Optional URL
118
+	 * @param bool   $useBrackets Whether to use square brackets when
119
+	 *                            multiple querystrings with the same name
120
+	 *                            exist
121
+	 */
122
+	function __construct($url = null, $useBrackets = true)
123
+	{
124
+		$HTTP_SERVER_VARS  = !empty($_SERVER) ? $_SERVER : $GLOBALS['HTTP_SERVER_VARS'];
125
+
126
+		$this->useBrackets = $useBrackets;
127
+		$this->url         = $url;
128
+		$this->user        = '';
129
+		$this->pass        = '';
130
+		$this->host        = '';
131
+		$this->port        = 80;
132
+		$this->path        = '';
133
+		$this->querystring = array();
134
+		$this->anchor      = '';
135
+
136
+		// Only use defaults if not an absolute URL given
137
+		if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) {
138
+
139
+			$this->protocol    = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http');
140
+
141
+			/**
142
+			 * Figure out host/port
143
+			 */
144
+			if (!empty($HTTP_SERVER_VARS['HTTP_HOST']) AND preg_match('/^(.*)(:([0-9]+))?$/U', $HTTP_SERVER_VARS['HTTP_HOST'], $matches)) {
145
+				$host = $matches[1];
146
+				if (!empty($matches[3])) {
147
+					$port = $matches[3];
148
+				} else {
149
+					$port = $this->getStandardPort($this->protocol);
150
+				}
151
+			}
152
+
153
+			$this->user        = '';
154
+			$this->pass        = '';
155
+			$this->host        = !empty($host) ? $host : (isset($HTTP_SERVER_VARS['SERVER_NAME']) ? $HTTP_SERVER_VARS['SERVER_NAME'] : 'localhost');
156
+			$this->port        = !empty($port) ? $port : (isset($HTTP_SERVER_VARS['SERVER_PORT']) ? $HTTP_SERVER_VARS['SERVER_PORT'] : $this->getStandardPort($this->protocol));
157
+			$this->path        = !empty($HTTP_SERVER_VARS['PHP_SELF']) ? $HTTP_SERVER_VARS['PHP_SELF'] : '/';
158
+			$this->querystring = isset($HTTP_SERVER_VARS['QUERY_STRING']) ? $this->_parseRawQuerystring($HTTP_SERVER_VARS['QUERY_STRING']) : null;
159
+			$this->anchor      = '';
160
+		}
161
+
162
+		// Parse the url and store the various parts
163
+		if (!empty($url)) {
164
+			$urlinfo = parse_url($url);
165
+
166
+			// Default querystring
167
+			$this->querystring = array();
168
+
169
+			foreach ($urlinfo as $key => $value) {
170
+				switch ($key) {
171
+					case 'scheme':
172
+						$this->protocol = $value;
173
+						$this->port     = $this->getStandardPort($value);
174
+						break;
175
+
176
+					case 'user':
177
+					case 'pass':
178
+					case 'host':
179
+					case 'port':
180
+						$this->$key = $value;
181
+						break;
182
+
183
+					case 'path':
184
+						if ($value{0} == '/') {
185
+							$this->path = $value;
186
+						} else {
187
+							$path = dirname($this->path) == DIRECTORY_SEPARATOR ? '' : dirname($this->path);
188
+							$this->path = sprintf('%s/%s', $path, $value);
189
+						}
190
+						break;
191
+
192
+					case 'query':
193
+						$this->querystring = $this->_parseRawQueryString($value);
194
+						break;
195
+
196
+					case 'fragment':
197
+						$this->anchor = $value;
198
+						break;
199
+				}
200
+			}
201
+		}
202
+	}
203
+
204
+	/**
205
+	 * Returns full url
206
+	 *
207
+	 * @return string Full url
208
+	 * @access public
209
+	 */
210
+	function getURL()
211
+	{
212
+		$querystring = $this->getQueryString();
213
+
214
+		$this->url = $this->protocol . '://'
215
+				   . $this->user . (!empty($this->pass) ? ':' : '')
216
+				   . $this->pass . (!empty($this->user) ? '@' : '')
217
+				   . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)
218
+				   . $this->path
219
+				   . (!empty($querystring) ? '?' . $querystring : '')
220
+				   . (!empty($this->anchor) ? '#' . $this->anchor : '');
221
+
222
+		return $this->url;
223
+	}
224
+
225
+	/**
226
+	 * Adds a querystring item
227
+	 *
228
+	 * @param  string $name       Name of item
229
+	 * @param  string $value      Value of item
230
+	 * @param  bool   $preencoded Whether value is urlencoded or not, default = not
231
+	 * @access public
232
+	 */
233
+	function addQueryString($name, $value, $preencoded = false)
234
+	{
235
+		if ($preencoded) {
236
+			$this->querystring[$name] = $value;
237
+		} else {
238
+			$this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value);
239
+		}
240
+	}
241
+
242
+	/**
243
+	 * Removes a querystring item
244
+	 *
245
+	 * @param  string $name Name of item
246
+	 * @access public
247
+	 */
248
+	function removeQueryString($name)
249
+	{
250
+		if (isset($this->querystring[$name])) {
251
+			unset($this->querystring[$name]);
252
+		}
253
+	}
254
+
255
+	/**
256
+	 * Sets the querystring to literally what you supply
257
+	 *
258
+	 * @param  string $querystring The querystring data. Should be of the format foo=bar&x=y etc
259
+	 * @access public
260
+	 */
261
+	function addRawQueryString($querystring)
262
+	{
263
+		$this->querystring = $this->_parseRawQueryString($querystring);
264
+	}
265
+
266
+	/**
267
+	 * Returns flat querystring
268
+	 *
269
+	 * @return string Querystring
270
+	 * @access public
271
+	 */
272
+	function getQueryString()
273
+	{
274
+		if (!empty($this->querystring)) {
275
+			foreach ($this->querystring as $name => $value) {
276
+				if (is_array($value)) {
277
+					foreach ($value as $k => $v) {
278
+						$querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v);
279
+					}
280
+				} elseif (!is_null($value)) {
281
+					$querystring[] = $name . '=' . $value;
282
+				} else {
283
+					$querystring[] = $name;
284
+				}
285
+			}
286
+			$querystring = implode(ini_get('arg_separator.output'), $querystring);
287
+		} else {
288
+			$querystring = '';
289
+		}
290
+
291
+		return $querystring;
292
+	}
293
+
294
+	/**
295
+	 * Parses raw querystring and returns an array of it
296
+	 *
297
+	 * @param  string  $querystring The querystring to parse
298
+	 * @return array                An array of the querystring data
299
+	 * @access private
300
+	 */
301
+	function _parseRawQuerystring($querystring)
302
+	{
303
+		$parts  = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);
304
+		$return = array();
305
+
306
+		foreach ($parts as $part) {
307
+			if (strpos($part, '=') !== false) {
308
+				$value = substr($part, strpos($part, '=') + 1);
309
+				$key   = substr($part, 0, strpos($part, '='));
310
+			} else {
311
+				$value = null;
312
+				$key   = $part;
313
+			}
314
+			if (substr($key, -2) == '[]') {
315
+				$key = substr($key, 0, -2);
316
+				if (@!is_array($return[$key])) {
317
+					$return[$key]   = array();
318
+					$return[$key][] = $value;
319
+				} else {
320
+					$return[$key][] = $value;
321
+				}
322
+			} elseif (!$this->useBrackets AND !empty($return[$key])) {
323
+				$return[$key]   = (array)$return[$key];
324
+				$return[$key][] = $value;
325
+			} else {
326
+				$return[$key] = $value;
327
+			}
328
+		}
329
+
330
+		return $return;
331
+	}
332
+
333
+	/**
334
+	 * Resolves //, ../ and ./ from a path and returns
335
+	 * the result. Eg:
336
+	 *
337
+	 * /foo/bar/../boo.php    => /foo/boo.php
338
+	 * /foo/bar/../../boo.php => /boo.php
339
+	 * /foo/bar/.././/boo.php => /foo/boo.php
340
+	 *
341
+	 * This method can also be called statically.
342
+	 *
343
+	 * @param  string $url URL path to resolve
344
+	 * @return string      The result
345
+	 */
346
+	function resolvePath($path)
347
+	{
348
+		$path = explode('/', str_replace('//', '/', $path));
349
+
350
+		for ($i=0; $i<count($path); $i++) {
351
+			if ($path[$i] == '.') {
352
+				unset($path[$i]);
353
+				$path = array_values($path);
354
+				$i--;
355
+
356
+			} elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {
357
+				unset($path[$i]);
358
+				unset($path[$i-1]);
359
+				$path = array_values($path);
360
+				$i -= 2;
361
+
362
+			} elseif ($path[$i] == '..' AND $i == 1 AND $path[0] == '') {
363
+				unset($path[$i]);
364
+				$path = array_values($path);
365
+				$i--;
366
+
367
+			} else {
368
+				continue;
369
+			}
370
+		}
371
+
372
+		return implode('/', $path);
373
+	}
374
+
375
+	/**
376
+	 * Returns the standard port number for a protocol
377
+	 *
378
+	 * @param  string  $scheme The protocol to lookup
379
+	 * @return integer         Port number or NULL if no scheme matches
380
+	 *
381
+	 * @author Philippe Jausions <[email protected]>
382
+	 */
383
+	function getStandardPort($scheme)
384
+	{
385
+		switch (strtolower($scheme)) {
386
+			case 'http':    return 80;
387
+			case 'https':   return 443;
388
+			case 'ftp':     return 21;
389
+			case 'imap':    return 143;
390
+			case 'imaps':   return 993;
391
+			case 'pop3':    return 110;
392
+			case 'pop3s':   return 995;
393
+			default:        return null;
394
+	   }
395
+	}
396
+
397
+	/**
398
+	 * Forces the URL to a particular protocol
399
+	 *
400
+	 * @param string  $protocol Protocol to force the URL to
401
+	 * @param integer $port     Optional port (standard port is used by default)
402
+	 */
403
+	function setProtocol($protocol, $port = null)
404
+	{
405
+		$this->protocol = $protocol;
406
+		$this->port = is_null($port) ? $this->getStandardPort() : $port;
407
+	}
408 408
 
409 409
 }
410 410
 ?>
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
         // Only use defaults if not an absolute URL given
137 137
         if (!preg_match('/^[a-z0-9]+:\/\//i', $url)) {
138 138
 
139
-            $this->protocol    = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http');
139
+            $this->protocol = (@$HTTP_SERVER_VARS['HTTPS'] == 'on' ? 'https' : 'http');
140 140
 
141 141
             /**
142 142
             * Figure out host/port
@@ -211,13 +211,13 @@  discard block
 block discarded – undo
211 211
     {
212 212
         $querystring = $this->getQueryString();
213 213
 
214
-        $this->url = $this->protocol . '://'
215
-                   . $this->user . (!empty($this->pass) ? ':' : '')
216
-                   . $this->pass . (!empty($this->user) ? '@' : '')
217
-                   . $this->host . ($this->port == $this->getStandardPort($this->protocol) ? '' : ':' . $this->port)
214
+        $this->url = $this->protocol.'://'
215
+                   . $this->user.(!empty($this->pass) ? ':' : '')
216
+                   . $this->pass.(!empty($this->user) ? '@' : '')
217
+                   . $this->host.($this->port == $this->getStandardPort($this->protocol) ? '' : ':'.$this->port)
218 218
                    . $this->path
219
-                   . (!empty($querystring) ? '?' . $querystring : '')
220
-                   . (!empty($this->anchor) ? '#' . $this->anchor : '');
219
+                   . (!empty($querystring) ? '?'.$querystring : '')
220
+                   . (!empty($this->anchor) ? '#'.$this->anchor : '');
221 221
 
222 222
         return $this->url;
223 223
     }
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
         if ($preencoded) {
236 236
             $this->querystring[$name] = $value;
237 237
         } else {
238
-            $this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value): rawurlencode($value);
238
+            $this->querystring[$name] = is_array($value) ? array_map('rawurlencode', $value) : rawurlencode($value);
239 239
         }
240 240
     }
241 241
 
@@ -275,10 +275,10 @@  discard block
 block discarded – undo
275 275
             foreach ($this->querystring as $name => $value) {
276 276
                 if (is_array($value)) {
277 277
                     foreach ($value as $k => $v) {
278
-                        $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name . '=' . $v);
278
+                        $querystring[] = $this->useBrackets ? sprintf('%s[%s]=%s', $name, $k, $v) : ($name.'='.$v);
279 279
                     }
280 280
                 } elseif (!is_null($value)) {
281
-                    $querystring[] = $name . '=' . $value;
281
+                    $querystring[] = $name.'='.$value;
282 282
                 } else {
283 283
                     $querystring[] = $name;
284 284
                 }
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
     */
301 301
     function _parseRawQuerystring($querystring)
302 302
     {
303
-        $parts  = preg_split('/[' . preg_quote(ini_get('arg_separator.input'), '/') . ']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);
303
+        $parts  = preg_split('/['.preg_quote(ini_get('arg_separator.input'), '/').']/', $querystring, -1, PREG_SPLIT_NO_EMPTY);
304 304
         $return = array();
305 305
 
306 306
         foreach ($parts as $part) {
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
                     $return[$key][] = $value;
321 321
                 }
322 322
             } elseif (!$this->useBrackets AND !empty($return[$key])) {
323
-                $return[$key]   = (array)$return[$key];
323
+                $return[$key]   = (array) $return[$key];
324 324
                 $return[$key][] = $value;
325 325
             } else {
326 326
                 $return[$key] = $value;
@@ -347,15 +347,15 @@  discard block
 block discarded – undo
347 347
     {
348 348
         $path = explode('/', str_replace('//', '/', $path));
349 349
 
350
-        for ($i=0; $i<count($path); $i++) {
350
+        for ($i = 0; $i < count($path); $i++) {
351 351
             if ($path[$i] == '.') {
352 352
                 unset($path[$i]);
353 353
                 $path = array_values($path);
354 354
                 $i--;
355 355
 
356
-            } elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != '') ) ) {
356
+            } elseif ($path[$i] == '..' AND ($i > 1 OR ($i == 1 AND $path[0] != ''))) {
357 357
                 unset($path[$i]);
358
-                unset($path[$i-1]);
358
+                unset($path[$i - 1]);
359 359
                 $path = array_values($path);
360 360
                 $i -= 2;
361 361
 
Please login to merge, or discard this patch.
libs/phpmailer/class.phpmailer.php 4 patches
Doc Comments   +27 added lines, -5 removed lines patch added patch discarded remove patch
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
    * Adds a "To" address.
320 320
    * @param string $address
321 321
    * @param string $name
322
-   * @return void
322
+   * @return boolean
323 323
    */
324 324
   function AddAddress($address, $name = '') {
325 325
     $cur = count($this->to);
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
    * mailer.
334 334
    * @param string $address
335 335
    * @param string $name
336
-   * @return void
336
+   * @return boolean
337 337
    */
338 338
   function AddCC($address, $name = '') {
339 339
     $cur = count($this->cc);
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
    * mailer.
348 348
    * @param string $address
349 349
    * @param string $name
350
-   * @return void
350
+   * @return boolean
351 351
    */
352 352
   function AddBCC($address, $name = '') {
353 353
     $cur = count($this->bcc);
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
    * Adds a "Reply-To" address.
360 360
    * @param string $address
361 361
    * @param string $name
362
-   * @return void
362
+   * @return boolean
363 363
    */
364 364
   function AddReplyTo($address, $name = '') {
365 365
     $cur = count($this->ReplyTo);
@@ -426,6 +426,8 @@  discard block
 block discarded – undo
426 426
   /**
427 427
    * Sends mail using the $Sendmail program.
428 428
    * @access private
429
+   * @param string $header
430
+   * @param string $body
429 431
    * @return bool
430 432
    */
431 433
   function SendmailSend($header, $body) {
@@ -457,6 +459,8 @@  discard block
 block discarded – undo
457 459
   /**
458 460
    * Sends mail using the PHP mail() function.
459 461
    * @access private
462
+   * @param string $header
463
+   * @param string $body
460 464
    * @return bool
461 465
    */
462 466
   function MailSend($header, $body) {
@@ -507,6 +511,8 @@  discard block
 block discarded – undo
507 511
    * Chris Ryan).  Returns bool.  Returns false if there is a
508 512
    * bad MAIL FROM, RCPT, or DATA input.
509 513
    * @access private
514
+   * @param string $header
515
+   * @param string $body
510 516
    * @return bool
511 517
    */
512 518
   function SmtpSend($header, $body) {
@@ -677,6 +683,7 @@  discard block
 block discarded – undo
677 683
   /**
678 684
    * Creates recipient headers.
679 685
    * @access private
686
+   * @param string $type
680 687
    * @return string
681 688
    */
682 689
   function AddrAppend($type, $addr) {
@@ -712,6 +719,8 @@  discard block
 block discarded – undo
712 719
    * automatically perform wrapping and for quoted-printable.
713 720
    * Original written by philippe.
714 721
    * @access private
722
+   * @param string $message
723
+   * @param integer $length
715 724
    * @return string
716 725
    */
717 726
   function WrapText($message, $length, $qp_mode = false) {
@@ -1040,6 +1049,9 @@  discard block
 block discarded – undo
1040 1049
   /**
1041 1050
    * Returns the start of a message boundary.
1042 1051
    * @access private
1052
+   * @param string $charSet
1053
+   * @param string $contentType
1054
+   * @param string $encoding
1043 1055
    */
1044 1056
   function GetBoundary($boundary, $charSet, $contentType, $encoding) {
1045 1057
     $result = '';
@@ -1094,6 +1106,10 @@  discard block
 block discarded – undo
1094 1106
    * @access private
1095 1107
    * @return string
1096 1108
    */
1109
+
1110
+  /**
1111
+   * @param string $name
1112
+   */
1097 1113
   function HeaderLine($name, $value) {
1098 1114
     return $name . ': ' . $value . $this->LE;
1099 1115
   }
@@ -1101,6 +1117,7 @@  discard block
 block discarded – undo
1101 1117
   /**
1102 1118
    * Returns a formatted mail line.
1103 1119
    * @access private
1120
+   * @param string $value
1104 1121
    * @return string
1105 1122
    */
1106 1123
   function TextLine($value) {
@@ -1259,6 +1276,7 @@  discard block
 block discarded – undo
1259 1276
   /**
1260 1277
    * Encode a header string to best of Q, B, quoted or none.
1261 1278
    * @access private
1279
+   * @param string $str
1262 1280
    * @return string
1263 1281
    */
1264 1282
   function EncodeHeader ($str, $position = 'text') {
@@ -1596,6 +1614,7 @@  discard block
 block discarded – undo
1596 1614
    * Adds the error message to the error container.
1597 1615
    * Returns void.
1598 1616
    * @access private
1617
+   * @param string $msg
1599 1618
    * @return void
1600 1619
    */
1601 1620
   function SetError($msg) {
@@ -1623,6 +1642,7 @@  discard block
 block discarded – undo
1623 1642
    * PHP 4.1.0+ as well as older versions.  Returns an empty string
1624 1643
    * if nothing is found.
1625 1644
    * @access private
1645
+   * @param string $varName
1626 1646
    * @return mixed
1627 1647
    */
1628 1648
   function ServerVar($varName) {
@@ -1663,6 +1683,7 @@  discard block
 block discarded – undo
1663 1683
   /**
1664 1684
    * Returns a message in the appropriate language.
1665 1685
    * @access private
1686
+   * @param string $key
1666 1687
    * @return string
1667 1688
    */
1668 1689
   function Lang($key) {
@@ -1708,6 +1729,7 @@  discard block
 block discarded – undo
1708 1729
   /**
1709 1730
    * Evaluates the message and returns modifications for inline images and backgrounds
1710 1731
    * @access public
1732
+   * @param string $message
1711 1733
    * @return $message
1712 1734
    */
1713 1735
   function MsgHTML($message,$basedir='') {
@@ -1745,7 +1767,7 @@  discard block
 block discarded – undo
1745 1767
   /**
1746 1768
    * Gets the mime type of the embedded or inline image
1747 1769
    * @access private
1748
-   * @return mime type of ext
1770
+   * @return string type of ext
1749 1771
    */
1750 1772
   function _mime_types($ext = '') {
1751 1773
     $mimes = array(
Please login to merge, or discard this patch.
Indentation   +1070 added lines, -1070 removed lines patch added patch discarded remove patch
@@ -271,11 +271,11 @@  discard block
 block discarded – undo
271 271
    * @return void
272 272
    */
273 273
   function IsHTML($bool) {
274
-    if($bool == true) {
275
-      $this->ContentType = 'text/html';
276
-    } else {
277
-      $this->ContentType = 'text/plain';
278
-    }
274
+	if($bool == true) {
275
+	  $this->ContentType = 'text/html';
276
+	} else {
277
+	  $this->ContentType = 'text/plain';
278
+	}
279 279
   }
280 280
 
281 281
   /**
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
    * @return void
284 284
    */
285 285
   function IsSMTP() {
286
-    $this->Mailer = 'smtp';
286
+	$this->Mailer = 'smtp';
287 287
   }
288 288
 
289 289
   /**
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
    * @return void
292 292
    */
293 293
   function IsMail() {
294
-    $this->Mailer = 'mail';
294
+	$this->Mailer = 'mail';
295 295
   }
296 296
 
297 297
   /**
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
    * @return void
300 300
    */
301 301
   function IsSendmail() {
302
-    $this->Mailer = 'sendmail';
302
+	$this->Mailer = 'sendmail';
303 303
   }
304 304
 
305 305
   /**
@@ -307,8 +307,8 @@  discard block
 block discarded – undo
307 307
    * @return void
308 308
    */
309 309
   function IsQmail() {
310
-    $this->Sendmail = '/var/qmail/bin/sendmail';
311
-    $this->Mailer = 'sendmail';
310
+	$this->Sendmail = '/var/qmail/bin/sendmail';
311
+	$this->Mailer = 'sendmail';
312 312
   }
313 313
 
314 314
   /////////////////////////////////////////////////
@@ -322,9 +322,9 @@  discard block
 block discarded – undo
322 322
    * @return void
323 323
    */
324 324
   function AddAddress($address, $name = '') {
325
-    $cur = count($this->to);
326
-    $this->to[$cur][0] = trim($address);
327
-    $this->to[$cur][1] = $name;
325
+	$cur = count($this->to);
326
+	$this->to[$cur][0] = trim($address);
327
+	$this->to[$cur][1] = $name;
328 328
   }
329 329
 
330 330
   /**
@@ -336,9 +336,9 @@  discard block
 block discarded – undo
336 336
    * @return void
337 337
    */
338 338
   function AddCC($address, $name = '') {
339
-    $cur = count($this->cc);
340
-    $this->cc[$cur][0] = trim($address);
341
-    $this->cc[$cur][1] = $name;
339
+	$cur = count($this->cc);
340
+	$this->cc[$cur][0] = trim($address);
341
+	$this->cc[$cur][1] = $name;
342 342
   }
343 343
 
344 344
   /**
@@ -350,9 +350,9 @@  discard block
 block discarded – undo
350 350
    * @return void
351 351
    */
352 352
   function AddBCC($address, $name = '') {
353
-    $cur = count($this->bcc);
354
-    $this->bcc[$cur][0] = trim($address);
355
-    $this->bcc[$cur][1] = $name;
353
+	$cur = count($this->bcc);
354
+	$this->bcc[$cur][0] = trim($address);
355
+	$this->bcc[$cur][1] = $name;
356 356
   }
357 357
 
358 358
   /**
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
    * @return void
363 363
    */
364 364
   function AddReplyTo($address, $name = '') {
365
-    $cur = count($this->ReplyTo);
366
-    $this->ReplyTo[$cur][0] = trim($address);
367
-    $this->ReplyTo[$cur][1] = $name;
365
+	$cur = count($this->ReplyTo);
366
+	$this->ReplyTo[$cur][0] = trim($address);
367
+	$this->ReplyTo[$cur][1] = $name;
368 368
   }
369 369
 
370 370
   /////////////////////////////////////////////////
@@ -378,49 +378,49 @@  discard block
 block discarded – undo
378 378
    * @return bool
379 379
    */
380 380
   function Send() {
381
-    $header = '';
382
-    $body = '';
383
-    $result = true;
384
-
385
-    if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
386
-      $this->SetError($this->Lang('provide_address'));
387
-      return false;
388
-    }
389
-
390
-    /* Set whether the message is multipart/alternative */
391
-    if(!empty($this->AltBody)) {
392
-      $this->ContentType = 'multipart/alternative';
393
-    }
394
-
395
-    $this->error_count = 0; // reset errors
396
-    $this->SetMessageType();
397
-    $header .= $this->CreateHeader();
398
-    $body = $this->CreateBody();
399
-
400
-    if($body == '') {
401
-      return false;
402
-    }
403
-
404
-    /* Choose the mailer */
405
-    switch($this->Mailer) {
406
-      case 'sendmail':
407
-        $result = $this->SendmailSend($header, $body);
408
-        break;
409
-      case 'smtp':
410
-        $result = $this->SmtpSend($header, $body);
411
-        break;
412
-      case 'mail':
413
-        $result = $this->MailSend($header, $body);
414
-        break;
415
-      default:
416
-        $result = $this->MailSend($header, $body);
417
-        break;
418
-        //$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
419
-        //$result = false;
420
-        //break;
421
-    }
422
-
423
-    return $result;
381
+	$header = '';
382
+	$body = '';
383
+	$result = true;
384
+
385
+	if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
386
+	  $this->SetError($this->Lang('provide_address'));
387
+	  return false;
388
+	}
389
+
390
+	/* Set whether the message is multipart/alternative */
391
+	if(!empty($this->AltBody)) {
392
+	  $this->ContentType = 'multipart/alternative';
393
+	}
394
+
395
+	$this->error_count = 0; // reset errors
396
+	$this->SetMessageType();
397
+	$header .= $this->CreateHeader();
398
+	$body = $this->CreateBody();
399
+
400
+	if($body == '') {
401
+	  return false;
402
+	}
403
+
404
+	/* Choose the mailer */
405
+	switch($this->Mailer) {
406
+	  case 'sendmail':
407
+		$result = $this->SendmailSend($header, $body);
408
+		break;
409
+	  case 'smtp':
410
+		$result = $this->SmtpSend($header, $body);
411
+		break;
412
+	  case 'mail':
413
+		$result = $this->MailSend($header, $body);
414
+		break;
415
+	  default:
416
+		$result = $this->MailSend($header, $body);
417
+		break;
418
+		//$this->SetError($this->Mailer . $this->Lang('mailer_not_supported'));
419
+		//$result = false;
420
+		//break;
421
+	}
422
+
423
+	return $result;
424 424
   }
425 425
 
426 426
   /**
@@ -429,29 +429,29 @@  discard block
 block discarded – undo
429 429
    * @return bool
430 430
    */
431 431
   function SendmailSend($header, $body) {
432
-    if ($this->Sender != '') {
433
-      $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
434
-    } else {
435
-      $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
436
-    }
437
-
438
-    if(!@$mail = popen($sendmail, 'w')) {
439
-      $this->SetError($this->Lang('execute') . $this->Sendmail);
440
-      return false;
441
-    }
442
-
443
-    fputs($mail, $header);
444
-    fputs($mail, $body);
445
-
446
-    $result = pclose($mail);
447
-    if (version_compare(phpversion(), '4.2.3') == -1) {
448
-      $result = $result >> 8 & 0xFF;
449
-    }
450
-    if($result != 0) {
451
-      $this->SetError($this->Lang('execute') . $this->Sendmail);
452
-      return false;
453
-    }
454
-    return true;
432
+	if ($this->Sender != '') {
433
+	  $sendmail = sprintf("%s -oi -f %s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
434
+	} else {
435
+	  $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
436
+	}
437
+
438
+	if(!@$mail = popen($sendmail, 'w')) {
439
+	  $this->SetError($this->Lang('execute') . $this->Sendmail);
440
+	  return false;
441
+	}
442
+
443
+	fputs($mail, $header);
444
+	fputs($mail, $body);
445
+
446
+	$result = pclose($mail);
447
+	if (version_compare(phpversion(), '4.2.3') == -1) {
448
+	  $result = $result >> 8 & 0xFF;
449
+	}
450
+	if($result != 0) {
451
+	  $this->SetError($this->Lang('execute') . $this->Sendmail);
452
+	  return false;
453
+	}
454
+	return true;
455 455
   }
456 456
 
457 457
   /**
@@ -461,45 +461,45 @@  discard block
 block discarded – undo
461 461
    */
462 462
   function MailSend($header, $body) {
463 463
 
464
-    $to = '';
465
-    for($i = 0; $i < count($this->to); $i++) {
466
-      if($i != 0) { $to .= ', '; }
467
-      $to .= $this->AddrFormat($this->to[$i]);
468
-    }
469
-
470
-    $toArr = split(',', $to);
471
-
472
-    $params = sprintf("-oi -f %s", $this->Sender);
473
-    if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
474
-      $old_from = ini_get('sendmail_from');
475
-      ini_set('sendmail_from', $this->Sender);
476
-      if ($this->SingleTo === true && count($toArr) > 1) {
477
-        foreach ($toArr as $key => $val) {
478
-          $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
479
-        }
480
-      } else {
481
-        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
482
-      }
483
-    } else {
484
-      if ($this->SingleTo === true && count($toArr) > 1) {
485
-        foreach ($toArr as $key => $val) {
486
-          $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
487
-        }
488
-      } else {
489
-        $rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
490
-      }
491
-    }
492
-
493
-    if (isset($old_from)) {
494
-      ini_set('sendmail_from', $old_from);
495
-    }
496
-
497
-    if(!$rt) {
498
-      $this->SetError($this->Lang('instantiate'));
499
-      return false;
500
-    }
501
-
502
-    return true;
464
+	$to = '';
465
+	for($i = 0; $i < count($this->to); $i++) {
466
+	  if($i != 0) { $to .= ', '; }
467
+	  $to .= $this->AddrFormat($this->to[$i]);
468
+	}
469
+
470
+	$toArr = split(',', $to);
471
+
472
+	$params = sprintf("-oi -f %s", $this->Sender);
473
+	if ($this->Sender != '' && strlen(ini_get('safe_mode')) < 1) {
474
+	  $old_from = ini_get('sendmail_from');
475
+	  ini_set('sendmail_from', $this->Sender);
476
+	  if ($this->SingleTo === true && count($toArr) > 1) {
477
+		foreach ($toArr as $key => $val) {
478
+		  $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
479
+		}
480
+	  } else {
481
+		$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
482
+	  }
483
+	} else {
484
+	  if ($this->SingleTo === true && count($toArr) > 1) {
485
+		foreach ($toArr as $key => $val) {
486
+		  $rt = @mail($val, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header, $params);
487
+		}
488
+	  } else {
489
+		$rt = @mail($to, $this->EncodeHeader($this->SecureHeader($this->Subject)), $body, $header);
490
+	  }
491
+	}
492
+
493
+	if (isset($old_from)) {
494
+	  ini_set('sendmail_from', $old_from);
495
+	}
496
+
497
+	if(!$rt) {
498
+	  $this->SetError($this->Lang('instantiate'));
499
+	  return false;
500
+	}
501
+
502
+	return true;
503 503
   }
504 504
 
505 505
   /**
@@ -510,64 +510,64 @@  discard block
 block discarded – undo
510 510
    * @return bool
511 511
    */
512 512
   function SmtpSend($header, $body) {
513
-    include_once($this->PluginDir . 'class.smtp.php');
514
-    $error = '';
515
-    $bad_rcpt = array();
516
-
517
-    if(!$this->SmtpConnect()) {
518
-      return false;
519
-    }
520
-
521
-    $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
522
-    if(!$this->smtp->Mail($smtp_from)) {
523
-      $error = $this->Lang('from_failed') . $smtp_from;
524
-      $this->SetError($error);
525
-      $this->smtp->Reset();
526
-      return false;
527
-    }
528
-
529
-    /* Attempt to send attach all recipients */
530
-    for($i = 0; $i < count($this->to); $i++) {
531
-      if(!$this->smtp->Recipient($this->to[$i][0])) {
532
-        $bad_rcpt[] = $this->to[$i][0];
533
-      }
534
-    }
535
-    for($i = 0; $i < count($this->cc); $i++) {
536
-      if(!$this->smtp->Recipient($this->cc[$i][0])) {
537
-        $bad_rcpt[] = $this->cc[$i][0];
538
-      }
539
-    }
540
-    for($i = 0; $i < count($this->bcc); $i++) {
541
-      if(!$this->smtp->Recipient($this->bcc[$i][0])) {
542
-        $bad_rcpt[] = $this->bcc[$i][0];
543
-      }
544
-    }
545
-
546
-    if(count($bad_rcpt) > 0) { // Create error message
547
-      for($i = 0; $i < count($bad_rcpt); $i++) {
548
-        if($i != 0) {
549
-          $error .= ', ';
550
-        }
551
-        $error .= $bad_rcpt[$i];
552
-      }
553
-      $error = $this->Lang('recipients_failed') . $error;
554
-      $this->SetError($error);
555
-      $this->smtp->Reset();
556
-      return false;
557
-    }
558
-
559
-    if(!$this->smtp->Data($header . $body)) {
560
-      $this->SetError($this->Lang('data_not_accepted'));
561
-      $this->smtp->Reset();
562
-      return false;
563
-    }
564
-    if($this->SMTPKeepAlive == true) {
565
-      $this->smtp->Reset();
566
-    } else {
567
-      $this->SmtpClose();
568
-    }
569
-
570
-    return true;
513
+	include_once($this->PluginDir . 'class.smtp.php');
514
+	$error = '';
515
+	$bad_rcpt = array();
516
+
517
+	if(!$this->SmtpConnect()) {
518
+	  return false;
519
+	}
520
+
521
+	$smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
522
+	if(!$this->smtp->Mail($smtp_from)) {
523
+	  $error = $this->Lang('from_failed') . $smtp_from;
524
+	  $this->SetError($error);
525
+	  $this->smtp->Reset();
526
+	  return false;
527
+	}
528
+
529
+	/* Attempt to send attach all recipients */
530
+	for($i = 0; $i < count($this->to); $i++) {
531
+	  if(!$this->smtp->Recipient($this->to[$i][0])) {
532
+		$bad_rcpt[] = $this->to[$i][0];
533
+	  }
534
+	}
535
+	for($i = 0; $i < count($this->cc); $i++) {
536
+	  if(!$this->smtp->Recipient($this->cc[$i][0])) {
537
+		$bad_rcpt[] = $this->cc[$i][0];
538
+	  }
539
+	}
540
+	for($i = 0; $i < count($this->bcc); $i++) {
541
+	  if(!$this->smtp->Recipient($this->bcc[$i][0])) {
542
+		$bad_rcpt[] = $this->bcc[$i][0];
543
+	  }
544
+	}
545
+
546
+	if(count($bad_rcpt) > 0) { // Create error message
547
+	  for($i = 0; $i < count($bad_rcpt); $i++) {
548
+		if($i != 0) {
549
+		  $error .= ', ';
550
+		}
551
+		$error .= $bad_rcpt[$i];
552
+	  }
553
+	  $error = $this->Lang('recipients_failed') . $error;
554
+	  $this->SetError($error);
555
+	  $this->smtp->Reset();
556
+	  return false;
557
+	}
558
+
559
+	if(!$this->smtp->Data($header . $body)) {
560
+	  $this->SetError($this->Lang('data_not_accepted'));
561
+	  $this->smtp->Reset();
562
+	  return false;
563
+	}
564
+	if($this->SMTPKeepAlive == true) {
565
+	  $this->smtp->Reset();
566
+	} else {
567
+	  $this->SmtpClose();
568
+	}
569
+
570
+	return true;
571 571
   }
572 572
 
573 573
   /**
@@ -577,49 +577,49 @@  discard block
 block discarded – undo
577 577
    * @return bool
578 578
    */
579 579
   function SmtpConnect() {
580
-    if($this->smtp == NULL) {
581
-      $this->smtp = new SMTP();
582
-    }
583
-
584
-    $this->smtp->do_debug = $this->SMTPDebug;
585
-    $hosts = explode(';', $this->Host);
586
-    $index = 0;
587
-    $connection = ($this->smtp->Connected());
588
-
589
-    /* Retry while there is no connection */
590
-    while($index < count($hosts) && $connection == false) {
591
-      $hostinfo = array();
592
-      if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
593
-        $host = $hostinfo[1];
594
-        $port = $hostinfo[2];
595
-      } else {
596
-        $host = $hosts[$index];
597
-        $port = $this->Port;
598
-      }
599
-
600
-      if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
601
-        if ($this->Helo != '') {
602
-          $this->smtp->Hello($this->Helo);
603
-        } else {
604
-          $this->smtp->Hello($this->ServerHostname());
605
-        }
606
-
607
-        $connection = true;
608
-        if($this->SMTPAuth) {
609
-          if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
610
-            $this->SetError($this->Lang('authenticate'));
611
-            $this->smtp->Reset();
612
-            $connection = false;
613
-          }
614
-        }
615
-      }
616
-      $index++;
617
-    }
618
-    if(!$connection) {
619
-      $this->SetError($this->Lang('connect_host'));
620
-    }
621
-
622
-    return $connection;
580
+	if($this->smtp == NULL) {
581
+	  $this->smtp = new SMTP();
582
+	}
583
+
584
+	$this->smtp->do_debug = $this->SMTPDebug;
585
+	$hosts = explode(';', $this->Host);
586
+	$index = 0;
587
+	$connection = ($this->smtp->Connected());
588
+
589
+	/* Retry while there is no connection */
590
+	while($index < count($hosts) && $connection == false) {
591
+	  $hostinfo = array();
592
+	  if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
593
+		$host = $hostinfo[1];
594
+		$port = $hostinfo[2];
595
+	  } else {
596
+		$host = $hosts[$index];
597
+		$port = $this->Port;
598
+	  }
599
+
600
+	  if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
601
+		if ($this->Helo != '') {
602
+		  $this->smtp->Hello($this->Helo);
603
+		} else {
604
+		  $this->smtp->Hello($this->ServerHostname());
605
+		}
606
+
607
+		$connection = true;
608
+		if($this->SMTPAuth) {
609
+		  if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
610
+			$this->SetError($this->Lang('authenticate'));
611
+			$this->smtp->Reset();
612
+			$connection = false;
613
+		  }
614
+		}
615
+	  }
616
+	  $index++;
617
+	}
618
+	if(!$connection) {
619
+	  $this->SetError($this->Lang('connect_host'));
620
+	}
621
+
622
+	return $connection;
623 623
   }
624 624
 
625 625
   /**
@@ -627,12 +627,12 @@  discard block
 block discarded – undo
627 627
    * @return void
628 628
    */
629 629
   function SmtpClose() {
630
-    if($this->smtp != NULL) {
631
-      if($this->smtp->Connected()) {
632
-        $this->smtp->Quit();
633
-        $this->smtp->Close();
634
-      }
635
-    }
630
+	if($this->smtp != NULL) {
631
+	  if($this->smtp->Connected()) {
632
+		$this->smtp->Quit();
633
+		$this->smtp->Close();
634
+	  }
635
+	}
636 636
   }
637 637
 
638 638
   /**
@@ -645,29 +645,29 @@  discard block
 block discarded – undo
645 645
    * @return bool
646 646
    */
647 647
   function SetLanguage($lang_type, $lang_path = 'language/') {
648
-    if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
649
-      include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
650
-    } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
651
-      include($lang_path.'phpmailer.lang-en.php');
652
-    } else {
653
-      $PHPMAILER_LANG = array();
654
-      $PHPMAILER_LANG["provide_address"]      = 'You must provide at least one ' .
655
-      $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
656
-      $PHPMAILER_LANG["execute"]              = 'Could not execute: ';
657
-      $PHPMAILER_LANG["instantiate"]          = 'Could not instantiate mail function.';
658
-      $PHPMAILER_LANG["authenticate"]         = 'SMTP Error: Could not authenticate.';
659
-      $PHPMAILER_LANG["from_failed"]          = 'The following From address failed: ';
660
-      $PHPMAILER_LANG["recipients_failed"]    = 'SMTP Error: The following ' .
661
-      $PHPMAILER_LANG["data_not_accepted"]    = 'SMTP Error: Data not accepted.';
662
-      $PHPMAILER_LANG["connect_host"]         = 'SMTP Error: Could not connect to SMTP host.';
663
-      $PHPMAILER_LANG["file_access"]          = 'Could not access file: ';
664
-      $PHPMAILER_LANG["file_open"]            = 'File Error: Could not open file: ';
665
-      $PHPMAILER_LANG["encoding"]             = 'Unknown encoding: ';
666
-      $PHPMAILER_LANG["signing"]              = 'Signing Error: ';
667
-    }
668
-    $this->language = $PHPMAILER_LANG;
669
-
670
-    return true;
648
+	if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
649
+	  include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
650
+	} elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
651
+	  include($lang_path.'phpmailer.lang-en.php');
652
+	} else {
653
+	  $PHPMAILER_LANG = array();
654
+	  $PHPMAILER_LANG["provide_address"]      = 'You must provide at least one ' .
655
+	  $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
656
+	  $PHPMAILER_LANG["execute"]              = 'Could not execute: ';
657
+	  $PHPMAILER_LANG["instantiate"]          = 'Could not instantiate mail function.';
658
+	  $PHPMAILER_LANG["authenticate"]         = 'SMTP Error: Could not authenticate.';
659
+	  $PHPMAILER_LANG["from_failed"]          = 'The following From address failed: ';
660
+	  $PHPMAILER_LANG["recipients_failed"]    = 'SMTP Error: The following ' .
661
+	  $PHPMAILER_LANG["data_not_accepted"]    = 'SMTP Error: Data not accepted.';
662
+	  $PHPMAILER_LANG["connect_host"]         = 'SMTP Error: Could not connect to SMTP host.';
663
+	  $PHPMAILER_LANG["file_access"]          = 'Could not access file: ';
664
+	  $PHPMAILER_LANG["file_open"]            = 'File Error: Could not open file: ';
665
+	  $PHPMAILER_LANG["encoding"]             = 'Unknown encoding: ';
666
+	  $PHPMAILER_LANG["signing"]              = 'Signing Error: ';
667
+	}
668
+	$this->language = $PHPMAILER_LANG;
669
+
670
+	return true;
671 671
   }
672 672
 
673 673
   /////////////////////////////////////////////////
@@ -680,16 +680,16 @@  discard block
 block discarded – undo
680 680
    * @return string
681 681
    */
682 682
   function AddrAppend($type, $addr) {
683
-    $addr_str = $type . ': ';
684
-    $addr_str .= $this->AddrFormat($addr[0]);
685
-    if(count($addr) > 1) {
686
-      for($i = 1; $i < count($addr); $i++) {
687
-        $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
688
-      }
689
-    }
690
-    $addr_str .= $this->LE;
691
-
692
-    return $addr_str;
683
+	$addr_str = $type . ': ';
684
+	$addr_str .= $this->AddrFormat($addr[0]);
685
+	if(count($addr) > 1) {
686
+	  for($i = 1; $i < count($addr); $i++) {
687
+		$addr_str .= ', ' . $this->AddrFormat($addr[$i]);
688
+	  }
689
+	}
690
+	$addr_str .= $this->LE;
691
+
692
+	return $addr_str;
693 693
   }
694 694
 
695 695
   /**
@@ -698,13 +698,13 @@  discard block
 block discarded – undo
698 698
    * @return string
699 699
    */
700 700
   function AddrFormat($addr) {
701
-    if(empty($addr[1])) {
702
-      $formatted = $this->SecureHeader($addr[0]);
703
-    } else {
704
-      $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
705
-    }
701
+	if(empty($addr[1])) {
702
+	  $formatted = $this->SecureHeader($addr[0]);
703
+	} else {
704
+	  $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
705
+	}
706 706
 
707
-    return $formatted;
707
+	return $formatted;
708 708
   }
709 709
 
710 710
   /**
@@ -715,76 +715,76 @@  discard block
 block discarded – undo
715 715
    * @return string
716 716
    */
717 717
   function WrapText($message, $length, $qp_mode = false) {
718
-    $soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
719
-    // If utf-8 encoding is used, we will need to make sure we don't
720
-    // split multibyte characters when we wrap
721
-    $is_utf8 = (strtolower($this->CharSet) == "utf-8");
722
-
723
-    $message = $this->FixEOL($message);
724
-    if (substr($message, -1) == $this->LE) {
725
-      $message = substr($message, 0, -1);
726
-    }
727
-
728
-    $line = explode($this->LE, $message);
729
-    $message = '';
730
-    for ($i=0 ;$i < count($line); $i++) {
731
-      $line_part = explode(' ', $line[$i]);
732
-      $buf = '';
733
-      for ($e = 0; $e<count($line_part); $e++) {
734
-        $word = $line_part[$e];
735
-        if ($qp_mode and (strlen($word) > $length)) {
736
-          $space_left = $length - strlen($buf) - 1;
737
-          if ($e != 0) {
738
-            if ($space_left > 20) {
739
-              $len = $space_left;
740
-              if ($is_utf8) {
741
-                $len = $this->UTF8CharBoundary($word, $len);
742
-              } elseif (substr($word, $len - 1, 1) == "=") {
743
-                $len--;
744
-              } elseif (substr($word, $len - 2, 1) == "=") {
745
-                $len -= 2;
746
-              }
747
-              $part = substr($word, 0, $len);
748
-              $word = substr($word, $len);
749
-              $buf .= ' ' . $part;
750
-              $message .= $buf . sprintf("=%s", $this->LE);
751
-            } else {
752
-              $message .= $buf . $soft_break;
753
-            }
754
-            $buf = '';
755
-          }
756
-          while (strlen($word) > 0) {
757
-            $len = $length;
758
-            if ($is_utf8) {
759
-              $len = $this->UTF8CharBoundary($word, $len);
760
-            } elseif (substr($word, $len - 1, 1) == "=") {
761
-              $len--;
762
-            } elseif (substr($word, $len - 2, 1) == "=") {
763
-              $len -= 2;
764
-            }
765
-            $part = substr($word, 0, $len);
766
-            $word = substr($word, $len);
767
-
768
-            if (strlen($word) > 0) {
769
-              $message .= $part . sprintf("=%s", $this->LE);
770
-            } else {
771
-              $buf = $part;
772
-            }
773
-          }
774
-        } else {
775
-          $buf_o = $buf;
776
-          $buf .= ($e == 0) ? $word : (' ' . $word);
777
-
778
-          if (strlen($buf) > $length and $buf_o != '') {
779
-            $message .= $buf_o . $soft_break;
780
-            $buf = $word;
781
-          }
782
-        }
783
-      }
784
-      $message .= $buf . $this->LE;
785
-    }
786
-
787
-    return $message;
718
+	$soft_break = ($qp_mode) ? sprintf(" =%s", $this->LE) : $this->LE;
719
+	// If utf-8 encoding is used, we will need to make sure we don't
720
+	// split multibyte characters when we wrap
721
+	$is_utf8 = (strtolower($this->CharSet) == "utf-8");
722
+
723
+	$message = $this->FixEOL($message);
724
+	if (substr($message, -1) == $this->LE) {
725
+	  $message = substr($message, 0, -1);
726
+	}
727
+
728
+	$line = explode($this->LE, $message);
729
+	$message = '';
730
+	for ($i=0 ;$i < count($line); $i++) {
731
+	  $line_part = explode(' ', $line[$i]);
732
+	  $buf = '';
733
+	  for ($e = 0; $e<count($line_part); $e++) {
734
+		$word = $line_part[$e];
735
+		if ($qp_mode and (strlen($word) > $length)) {
736
+		  $space_left = $length - strlen($buf) - 1;
737
+		  if ($e != 0) {
738
+			if ($space_left > 20) {
739
+			  $len = $space_left;
740
+			  if ($is_utf8) {
741
+				$len = $this->UTF8CharBoundary($word, $len);
742
+			  } elseif (substr($word, $len - 1, 1) == "=") {
743
+				$len--;
744
+			  } elseif (substr($word, $len - 2, 1) == "=") {
745
+				$len -= 2;
746
+			  }
747
+			  $part = substr($word, 0, $len);
748
+			  $word = substr($word, $len);
749
+			  $buf .= ' ' . $part;
750
+			  $message .= $buf . sprintf("=%s", $this->LE);
751
+			} else {
752
+			  $message .= $buf . $soft_break;
753
+			}
754
+			$buf = '';
755
+		  }
756
+		  while (strlen($word) > 0) {
757
+			$len = $length;
758
+			if ($is_utf8) {
759
+			  $len = $this->UTF8CharBoundary($word, $len);
760
+			} elseif (substr($word, $len - 1, 1) == "=") {
761
+			  $len--;
762
+			} elseif (substr($word, $len - 2, 1) == "=") {
763
+			  $len -= 2;
764
+			}
765
+			$part = substr($word, 0, $len);
766
+			$word = substr($word, $len);
767
+
768
+			if (strlen($word) > 0) {
769
+			  $message .= $part . sprintf("=%s", $this->LE);
770
+			} else {
771
+			  $buf = $part;
772
+			}
773
+		  }
774
+		} else {
775
+		  $buf_o = $buf;
776
+		  $buf .= ($e == 0) ? $word : (' ' . $word);
777
+
778
+		  if (strlen($buf) > $length and $buf_o != '') {
779
+			$message .= $buf_o . $soft_break;
780
+			$buf = $word;
781
+		  }
782
+		}
783
+	  }
784
+	  $message .= $buf . $this->LE;
785
+	}
786
+
787
+	return $message;
788 788
   }
789 789
 
790 790
   /**
@@ -797,35 +797,35 @@  discard block
 block discarded – undo
797 797
    * @return int
798 798
    */
799 799
   function UTF8CharBoundary($encodedText, $maxLength) {
800
-    $foundSplitPos = false;
801
-    $lookBack = 3;
802
-    while (!$foundSplitPos) {
803
-      $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
804
-      $encodedCharPos = strpos($lastChunk, "=");
805
-      if ($encodedCharPos !== false) {
806
-        // Found start of encoded character byte within $lookBack block.
807
-        // Check the encoded byte value (the 2 chars after the '=')
808
-        $hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
809
-        $dec = hexdec($hex);
810
-        if ($dec < 128) { // Single byte character.
811
-          // If the encoded char was found at pos 0, it will fit
812
-          // otherwise reduce maxLength to start of the encoded char
813
-          $maxLength = ($encodedCharPos == 0) ? $maxLength :
814
-          $maxLength - ($lookBack - $encodedCharPos);
815
-          $foundSplitPos = true;
816
-        } elseif ($dec >= 192) { // First byte of a multi byte character
817
-          // Reduce maxLength to split at start of character
818
-          $maxLength = $maxLength - ($lookBack - $encodedCharPos);
819
-          $foundSplitPos = true;
820
-        } elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
821
-          $lookBack += 3;
822
-        }
823
-      } else {
824
-        // No encoded character found
825
-        $foundSplitPos = true;
826
-      }
827
-    }
828
-    return $maxLength;
800
+	$foundSplitPos = false;
801
+	$lookBack = 3;
802
+	while (!$foundSplitPos) {
803
+	  $lastChunk = substr($encodedText, $maxLength - $lookBack, $lookBack);
804
+	  $encodedCharPos = strpos($lastChunk, "=");
805
+	  if ($encodedCharPos !== false) {
806
+		// Found start of encoded character byte within $lookBack block.
807
+		// Check the encoded byte value (the 2 chars after the '=')
808
+		$hex = substr($encodedText, $maxLength - $lookBack + $encodedCharPos + 1, 2);
809
+		$dec = hexdec($hex);
810
+		if ($dec < 128) { // Single byte character.
811
+		  // If the encoded char was found at pos 0, it will fit
812
+		  // otherwise reduce maxLength to start of the encoded char
813
+		  $maxLength = ($encodedCharPos == 0) ? $maxLength :
814
+		  $maxLength - ($lookBack - $encodedCharPos);
815
+		  $foundSplitPos = true;
816
+		} elseif ($dec >= 192) { // First byte of a multi byte character
817
+		  // Reduce maxLength to split at start of character
818
+		  $maxLength = $maxLength - ($lookBack - $encodedCharPos);
819
+		  $foundSplitPos = true;
820
+		} elseif ($dec < 192) { // Middle byte of a multi byte character, look further back
821
+		  $lookBack += 3;
822
+		}
823
+	  } else {
824
+		// No encoded character found
825
+		$foundSplitPos = true;
826
+	  }
827
+	}
828
+	return $maxLength;
829 829
   }
830 830
 
831 831
   /**
@@ -834,20 +834,20 @@  discard block
 block discarded – undo
834 834
    * @return void
835 835
    */
836 836
   function SetWordWrap() {
837
-    if($this->WordWrap < 1) {
838
-      return;
839
-    }
840
-
841
-    switch($this->message_type) {
842
-      case 'alt':
843
-        /* fall through */
844
-      case 'alt_attachments':
845
-        $this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
846
-        break;
847
-      default:
848
-        $this->Body = $this->WrapText($this->Body, $this->WordWrap);
849
-        break;
850
-    }
837
+	if($this->WordWrap < 1) {
838
+	  return;
839
+	}
840
+
841
+	switch($this->message_type) {
842
+	  case 'alt':
843
+		/* fall through */
844
+	  case 'alt_attachments':
845
+		$this->AltBody = $this->WrapText($this->AltBody, $this->WordWrap);
846
+		break;
847
+	  default:
848
+		$this->Body = $this->WrapText($this->Body, $this->WordWrap);
849
+		break;
850
+	}
851 851
   }
852 852
 
853 853
   /**
@@ -856,75 +856,75 @@  discard block
 block discarded – undo
856 856
    * @return string
857 857
    */
858 858
   function CreateHeader() {
859
-    $result = '';
860
-
861
-    /* Set the boundaries */
862
-    $uniq_id = md5(uniqid(time()));
863
-    $this->boundary[1] = 'b1_' . $uniq_id;
864
-    $this->boundary[2] = 'b2_' . $uniq_id;
865
-
866
-    $result .= $this->HeaderLine('Date', $this->RFCDate());
867
-    if($this->Sender == '') {
868
-      $result .= $this->HeaderLine('Return-Path', trim($this->From));
869
-    } else {
870
-      $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
871
-    }
872
-
873
-    /* To be created automatically by mail() */
874
-    if($this->Mailer != 'mail') {
875
-      if(count($this->to) > 0) {
876
-        $result .= $this->AddrAppend('To', $this->to);
877
-      } elseif (count($this->cc) == 0) {
878
-        $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
879
-      }
880
-    }
881
-
882
-    $from = array();
883
-    $from[0][0] = trim($this->From);
884
-    $from[0][1] = $this->FromName;
885
-    $result .= $this->AddrAppend('From', $from);
886
-
887
-    /* sendmail and mail() extract Cc from the header before sending */
888
-    if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
889
-      $result .= $this->AddrAppend('Cc', $this->cc);
890
-    }
891
-
892
-    /* sendmail and mail() extract Bcc from the header before sending */
893
-    if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
894
-      $result .= $this->AddrAppend('Bcc', $this->bcc);
895
-    }
896
-
897
-    if(count($this->ReplyTo) > 0) {
898
-      $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
899
-    }
900
-
901
-    /* mail() sets the subject itself */
902
-    if($this->Mailer != 'mail') {
903
-      $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
904
-    }
905
-
906
-    if($this->MessageID != '') {
907
-      $result .= $this->HeaderLine('Message-ID',$this->MessageID);
908
-    } else {
909
-      $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
910
-    }
911
-    $result .= $this->HeaderLine('X-Priority', $this->Priority);
912
-    $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
913
-
914
-    if($this->ConfirmReadingTo != '') {
915
-      $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
916
-    }
917
-
918
-    // Add custom headers
919
-    for($index = 0; $index < count($this->CustomHeader); $index++) {
920
-      $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
921
-    }
922
-    if (!$this->sign_key_file) {
923
-      $result .= $this->HeaderLine('MIME-Version', '1.0');
924
-      $result .= $this->GetMailMIME();
925
-    }
926
-
927
-    return $result;
859
+	$result = '';
860
+
861
+	/* Set the boundaries */
862
+	$uniq_id = md5(uniqid(time()));
863
+	$this->boundary[1] = 'b1_' . $uniq_id;
864
+	$this->boundary[2] = 'b2_' . $uniq_id;
865
+
866
+	$result .= $this->HeaderLine('Date', $this->RFCDate());
867
+	if($this->Sender == '') {
868
+	  $result .= $this->HeaderLine('Return-Path', trim($this->From));
869
+	} else {
870
+	  $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
871
+	}
872
+
873
+	/* To be created automatically by mail() */
874
+	if($this->Mailer != 'mail') {
875
+	  if(count($this->to) > 0) {
876
+		$result .= $this->AddrAppend('To', $this->to);
877
+	  } elseif (count($this->cc) == 0) {
878
+		$result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
879
+	  }
880
+	}
881
+
882
+	$from = array();
883
+	$from[0][0] = trim($this->From);
884
+	$from[0][1] = $this->FromName;
885
+	$result .= $this->AddrAppend('From', $from);
886
+
887
+	/* sendmail and mail() extract Cc from the header before sending */
888
+	if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
889
+	  $result .= $this->AddrAppend('Cc', $this->cc);
890
+	}
891
+
892
+	/* sendmail and mail() extract Bcc from the header before sending */
893
+	if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
894
+	  $result .= $this->AddrAppend('Bcc', $this->bcc);
895
+	}
896
+
897
+	if(count($this->ReplyTo) > 0) {
898
+	  $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
899
+	}
900
+
901
+	/* mail() sets the subject itself */
902
+	if($this->Mailer != 'mail') {
903
+	  $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
904
+	}
905
+
906
+	if($this->MessageID != '') {
907
+	  $result .= $this->HeaderLine('Message-ID',$this->MessageID);
908
+	} else {
909
+	  $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
910
+	}
911
+	$result .= $this->HeaderLine('X-Priority', $this->Priority);
912
+	$result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
913
+
914
+	if($this->ConfirmReadingTo != '') {
915
+	  $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
916
+	}
917
+
918
+	// Add custom headers
919
+	for($index = 0; $index < count($this->CustomHeader); $index++) {
920
+	  $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
921
+	}
922
+	if (!$this->sign_key_file) {
923
+	  $result .= $this->HeaderLine('MIME-Version', '1.0');
924
+	  $result .= $this->GetMailMIME();
925
+	}
926
+
927
+	return $result;
928 928
   }
929 929
 
930 930
   /**
@@ -933,33 +933,33 @@  discard block
 block discarded – undo
933 933
    * @return string
934 934
    */
935 935
   function GetMailMIME() {
936
-    $result = '';
937
-    switch($this->message_type) {
938
-      case 'plain':
939
-        $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
940
-        $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
941
-        break;
942
-      case 'attachments':
943
-        /* fall through */
944
-      case 'alt_attachments':
945
-        if($this->InlineImageExists()){
946
-          $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
947
-        } else {
948
-          $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
949
-          $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
950
-        }
951
-        break;
952
-      case 'alt':
953
-        $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
954
-        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
955
-        break;
956
-    }
957
-
958
-    if($this->Mailer != 'mail') {
959
-      $result .= $this->LE.$this->LE;
960
-    }
961
-
962
-    return $result;
936
+	$result = '';
937
+	switch($this->message_type) {
938
+	  case 'plain':
939
+		$result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
940
+		$result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
941
+		break;
942
+	  case 'attachments':
943
+		/* fall through */
944
+	  case 'alt_attachments':
945
+		if($this->InlineImageExists()){
946
+		  $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
947
+		} else {
948
+		  $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
949
+		  $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
950
+		}
951
+		break;
952
+	  case 'alt':
953
+		$result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
954
+		$result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
955
+		break;
956
+	}
957
+
958
+	if($this->Mailer != 'mail') {
959
+	  $result .= $this->LE.$this->LE;
960
+	}
961
+
962
+	return $result;
963 963
   }
964 964
 
965 965
   /**
@@ -968,73 +968,73 @@  discard block
 block discarded – undo
968 968
    * @return string
969 969
    */
970 970
   function CreateBody() {
971
-    $result = '';
972
-    if ($this->sign_key_file) {
973
-      $result .= $this->GetMailMIME();
974
-    }
975
-
976
-    $this->SetWordWrap();
977
-
978
-    switch($this->message_type) {
979
-      case 'alt':
980
-        $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
981
-        $result .= $this->EncodeString($this->AltBody, $this->Encoding);
982
-        $result .= $this->LE.$this->LE;
983
-        $result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
984
-        $result .= $this->EncodeString($this->Body, $this->Encoding);
985
-        $result .= $this->LE.$this->LE;
986
-        $result .= $this->EndBoundary($this->boundary[1]);
987
-        break;
988
-      case 'plain':
989
-        $result .= $this->EncodeString($this->Body, $this->Encoding);
990
-        break;
991
-      case 'attachments':
992
-        $result .= $this->GetBoundary($this->boundary[1], '', '', '');
993
-        $result .= $this->EncodeString($this->Body, $this->Encoding);
994
-        $result .= $this->LE;
995
-        $result .= $this->AttachAll();
996
-        break;
997
-      case 'alt_attachments':
998
-        $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
999
-        $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
1000
-        $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
1001
-        $result .= $this->EncodeString($this->AltBody, $this->Encoding);
1002
-        $result .= $this->LE.$this->LE;
1003
-        $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
1004
-        $result .= $this->EncodeString($this->Body, $this->Encoding);
1005
-        $result .= $this->LE.$this->LE;
1006
-        $result .= $this->EndBoundary($this->boundary[2]);
1007
-        $result .= $this->AttachAll();
1008
-        break;
1009
-    }
1010
-
1011
-    if($this->IsError()) {
1012
-      $result = '';
1013
-    } else if ($this->sign_key_file) {
1014
-      $file = tempnam("", "mail");
1015
-      $fp = fopen($file, "w");
1016
-      fwrite($fp, $result);
1017
-      fclose($fp);
1018
-      $signed = tempnam("", "signed");
1019
-
1020
-      if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
1021
-        $fp = fopen($signed, "r");
1022
-        $result = fread($fp, filesize($this->sign_key_file));
1023
-        $result = '';
1024
-        while(!feof($fp)){
1025
-          $result = $result . fread($fp, 1024);
1026
-        }
1027
-        fclose($fp);
1028
-      } else {
1029
-        $this->SetError($this->Lang("signing").openssl_error_string());
1030
-        $result = '';
1031
-      }
1032
-
1033
-      unlink($file);
1034
-      unlink($signed);
1035
-    }
1036
-
1037
-    return $result;
971
+	$result = '';
972
+	if ($this->sign_key_file) {
973
+	  $result .= $this->GetMailMIME();
974
+	}
975
+
976
+	$this->SetWordWrap();
977
+
978
+	switch($this->message_type) {
979
+	  case 'alt':
980
+		$result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
981
+		$result .= $this->EncodeString($this->AltBody, $this->Encoding);
982
+		$result .= $this->LE.$this->LE;
983
+		$result .= $this->GetBoundary($this->boundary[1], '', 'text/html', '');
984
+		$result .= $this->EncodeString($this->Body, $this->Encoding);
985
+		$result .= $this->LE.$this->LE;
986
+		$result .= $this->EndBoundary($this->boundary[1]);
987
+		break;
988
+	  case 'plain':
989
+		$result .= $this->EncodeString($this->Body, $this->Encoding);
990
+		break;
991
+	  case 'attachments':
992
+		$result .= $this->GetBoundary($this->boundary[1], '', '', '');
993
+		$result .= $this->EncodeString($this->Body, $this->Encoding);
994
+		$result .= $this->LE;
995
+		$result .= $this->AttachAll();
996
+		break;
997
+	  case 'alt_attachments':
998
+		$result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
999
+		$result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
1000
+		$result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
1001
+		$result .= $this->EncodeString($this->AltBody, $this->Encoding);
1002
+		$result .= $this->LE.$this->LE;
1003
+		$result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
1004
+		$result .= $this->EncodeString($this->Body, $this->Encoding);
1005
+		$result .= $this->LE.$this->LE;
1006
+		$result .= $this->EndBoundary($this->boundary[2]);
1007
+		$result .= $this->AttachAll();
1008
+		break;
1009
+	}
1010
+
1011
+	if($this->IsError()) {
1012
+	  $result = '';
1013
+	} else if ($this->sign_key_file) {
1014
+	  $file = tempnam("", "mail");
1015
+	  $fp = fopen($file, "w");
1016
+	  fwrite($fp, $result);
1017
+	  fclose($fp);
1018
+	  $signed = tempnam("", "signed");
1019
+
1020
+	  if (@openssl_pkcs7_sign($file, $signed, "file://".$this->sign_cert_file, array("file://".$this->sign_key_file, $this->sign_key_pass), null)) {
1021
+		$fp = fopen($signed, "r");
1022
+		$result = fread($fp, filesize($this->sign_key_file));
1023
+		$result = '';
1024
+		while(!feof($fp)){
1025
+		  $result = $result . fread($fp, 1024);
1026
+		}
1027
+		fclose($fp);
1028
+	  } else {
1029
+		$this->SetError($this->Lang("signing").openssl_error_string());
1030
+		$result = '';
1031
+	  }
1032
+
1033
+	  unlink($file);
1034
+	  unlink($signed);
1035
+	}
1036
+
1037
+	return $result;
1038 1038
   }
1039 1039
 
1040 1040
   /**
@@ -1042,23 +1042,23 @@  discard block
 block discarded – undo
1042 1042
    * @access private
1043 1043
    */
1044 1044
   function GetBoundary($boundary, $charSet, $contentType, $encoding) {
1045
-    $result = '';
1046
-    if($charSet == '') {
1047
-      $charSet = $this->CharSet;
1048
-    }
1049
-    if($contentType == '') {
1050
-      $contentType = $this->ContentType;
1051
-    }
1052
-    if($encoding == '') {
1053
-      $encoding = $this->Encoding;
1054
-    }
1055
-    $result .= $this->TextLine('--' . $boundary);
1056
-    $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
1057
-    $result .= $this->LE;
1058
-    $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
1059
-    $result .= $this->LE;
1060
-
1061
-    return $result;
1045
+	$result = '';
1046
+	if($charSet == '') {
1047
+	  $charSet = $this->CharSet;
1048
+	}
1049
+	if($contentType == '') {
1050
+	  $contentType = $this->ContentType;
1051
+	}
1052
+	if($encoding == '') {
1053
+	  $encoding = $this->Encoding;
1054
+	}
1055
+	$result .= $this->TextLine('--' . $boundary);
1056
+	$result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
1057
+	$result .= $this->LE;
1058
+	$result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
1059
+	$result .= $this->LE;
1060
+
1061
+	return $result;
1062 1062
   }
1063 1063
 
1064 1064
   /**
@@ -1066,7 +1066,7 @@  discard block
 block discarded – undo
1066 1066
    * @access private
1067 1067
    */
1068 1068
   function EndBoundary($boundary) {
1069
-    return $this->LE . '--' . $boundary . '--' . $this->LE;
1069
+	return $this->LE . '--' . $boundary . '--' . $this->LE;
1070 1070
   }
1071 1071
 
1072 1072
   /**
@@ -1075,19 +1075,19 @@  discard block
 block discarded – undo
1075 1075
    * @return void
1076 1076
    */
1077 1077
   function SetMessageType() {
1078
-    if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
1079
-      $this->message_type = 'plain';
1080
-    } else {
1081
-      if(count($this->attachment) > 0) {
1082
-        $this->message_type = 'attachments';
1083
-      }
1084
-      if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
1085
-        $this->message_type = 'alt';
1086
-      }
1087
-      if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
1088
-        $this->message_type = 'alt_attachments';
1089
-      }
1090
-    }
1078
+	if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
1079
+	  $this->message_type = 'plain';
1080
+	} else {
1081
+	  if(count($this->attachment) > 0) {
1082
+		$this->message_type = 'attachments';
1083
+	  }
1084
+	  if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
1085
+		$this->message_type = 'alt';
1086
+	  }
1087
+	  if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
1088
+		$this->message_type = 'alt_attachments';
1089
+	  }
1090
+	}
1091 1091
   }
1092 1092
 
1093 1093
   /* Returns a formatted header line.
@@ -1095,7 +1095,7 @@  discard block
 block discarded – undo
1095 1095
    * @return string
1096 1096
    */
1097 1097
   function HeaderLine($name, $value) {
1098
-    return $name . ': ' . $value . $this->LE;
1098
+	return $name . ': ' . $value . $this->LE;
1099 1099
   }
1100 1100
 
1101 1101
   /**
@@ -1104,7 +1104,7 @@  discard block
 block discarded – undo
1104 1104
    * @return string
1105 1105
    */
1106 1106
   function TextLine($value) {
1107
-    return $value . $this->LE;
1107
+	return $value . $this->LE;
1108 1108
   }
1109 1109
 
1110 1110
   /////////////////////////////////////////////////
@@ -1122,27 +1122,27 @@  discard block
 block discarded – undo
1122 1122
    * @return bool
1123 1123
    */
1124 1124
   function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1125
-    if(!@is_file($path)) {
1126
-      $this->SetError($this->Lang('file_access') . $path);
1127
-      return false;
1128
-    }
1129
-
1130
-    $filename = basename($path);
1131
-    if($name == '') {
1132
-      $name = $filename;
1133
-    }
1134
-
1135
-    $cur = count($this->attachment);
1136
-    $this->attachment[$cur][0] = $path;
1137
-    $this->attachment[$cur][1] = $filename;
1138
-    $this->attachment[$cur][2] = $name;
1139
-    $this->attachment[$cur][3] = $encoding;
1140
-    $this->attachment[$cur][4] = $type;
1141
-    $this->attachment[$cur][5] = false; // isStringAttachment
1142
-    $this->attachment[$cur][6] = 'attachment';
1143
-    $this->attachment[$cur][7] = 0;
1144
-
1145
-    return true;
1125
+	if(!@is_file($path)) {
1126
+	  $this->SetError($this->Lang('file_access') . $path);
1127
+	  return false;
1128
+	}
1129
+
1130
+	$filename = basename($path);
1131
+	if($name == '') {
1132
+	  $name = $filename;
1133
+	}
1134
+
1135
+	$cur = count($this->attachment);
1136
+	$this->attachment[$cur][0] = $path;
1137
+	$this->attachment[$cur][1] = $filename;
1138
+	$this->attachment[$cur][2] = $name;
1139
+	$this->attachment[$cur][3] = $encoding;
1140
+	$this->attachment[$cur][4] = $type;
1141
+	$this->attachment[$cur][5] = false; // isStringAttachment
1142
+	$this->attachment[$cur][6] = 'attachment';
1143
+	$this->attachment[$cur][7] = 0;
1144
+
1145
+	return true;
1146 1146
   }
1147 1147
 
1148 1148
   /**
@@ -1152,55 +1152,55 @@  discard block
 block discarded – undo
1152 1152
    * @return string
1153 1153
    */
1154 1154
   function AttachAll() {
1155
-    /* Return text of body */
1156
-    $mime = array();
1157
-
1158
-    /* Add all attachments */
1159
-    for($i = 0; $i < count($this->attachment); $i++) {
1160
-      /* Check for string attachment */
1161
-      $bString = $this->attachment[$i][5];
1162
-      if ($bString) {
1163
-        $string = $this->attachment[$i][0];
1164
-      } else {
1165
-        $path = $this->attachment[$i][0];
1166
-      }
1167
-
1168
-      $filename    = $this->attachment[$i][1];
1169
-      $name        = $this->attachment[$i][2];
1170
-      $encoding    = $this->attachment[$i][3];
1171
-      $type        = $this->attachment[$i][4];
1172
-      $disposition = $this->attachment[$i][6];
1173
-      $cid         = $this->attachment[$i][7];
1174
-
1175
-      $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
1176
-      $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
1177
-      $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
1178
-
1179
-      if($disposition == 'inline') {
1180
-        $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
1181
-      }
1182
-
1183
-      $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
1184
-
1185
-      /* Encode as string attachment */
1186
-      if($bString) {
1187
-        $mime[] = $this->EncodeString($string, $encoding);
1188
-        if($this->IsError()) {
1189
-          return '';
1190
-        }
1191
-        $mime[] = $this->LE.$this->LE;
1192
-      } else {
1193
-        $mime[] = $this->EncodeFile($path, $encoding);
1194
-        if($this->IsError()) {
1195
-          return '';
1196
-        }
1197
-        $mime[] = $this->LE.$this->LE;
1198
-      }
1199
-    }
1200
-
1201
-    $mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
1202
-
1203
-    return join('', $mime);
1155
+	/* Return text of body */
1156
+	$mime = array();
1157
+
1158
+	/* Add all attachments */
1159
+	for($i = 0; $i < count($this->attachment); $i++) {
1160
+	  /* Check for string attachment */
1161
+	  $bString = $this->attachment[$i][5];
1162
+	  if ($bString) {
1163
+		$string = $this->attachment[$i][0];
1164
+	  } else {
1165
+		$path = $this->attachment[$i][0];
1166
+	  }
1167
+
1168
+	  $filename    = $this->attachment[$i][1];
1169
+	  $name        = $this->attachment[$i][2];
1170
+	  $encoding    = $this->attachment[$i][3];
1171
+	  $type        = $this->attachment[$i][4];
1172
+	  $disposition = $this->attachment[$i][6];
1173
+	  $cid         = $this->attachment[$i][7];
1174
+
1175
+	  $mime[] = sprintf("--%s%s", $this->boundary[1], $this->LE);
1176
+	  $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
1177
+	  $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
1178
+
1179
+	  if($disposition == 'inline') {
1180
+		$mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
1181
+	  }
1182
+
1183
+	  $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
1184
+
1185
+	  /* Encode as string attachment */
1186
+	  if($bString) {
1187
+		$mime[] = $this->EncodeString($string, $encoding);
1188
+		if($this->IsError()) {
1189
+		  return '';
1190
+		}
1191
+		$mime[] = $this->LE.$this->LE;
1192
+	  } else {
1193
+		$mime[] = $this->EncodeFile($path, $encoding);
1194
+		if($this->IsError()) {
1195
+		  return '';
1196
+		}
1197
+		$mime[] = $this->LE.$this->LE;
1198
+	  }
1199
+	}
1200
+
1201
+	$mime[] = sprintf("--%s--%s", $this->boundary[1], $this->LE);
1202
+
1203
+	return join('', $mime);
1204 1204
   }
1205 1205
 
1206 1206
   /**
@@ -1210,18 +1210,18 @@  discard block
 block discarded – undo
1210 1210
    * @return string
1211 1211
    */
1212 1212
   function EncodeFile ($path, $encoding = 'base64') {
1213
-    if(!@$fd = fopen($path, 'rb')) {
1214
-      $this->SetError($this->Lang('file_open') . $path);
1215
-      return '';
1216
-    }
1217
-    $magic_quotes = get_magic_quotes_runtime();
1218
-    set_magic_quotes_runtime(0);
1219
-    $file_buffer = fread($fd, filesize($path));
1220
-    $file_buffer = $this->EncodeString($file_buffer, $encoding);
1221
-    fclose($fd);
1222
-    set_magic_quotes_runtime($magic_quotes);
1223
-
1224
-    return $file_buffer;
1213
+	if(!@$fd = fopen($path, 'rb')) {
1214
+	  $this->SetError($this->Lang('file_open') . $path);
1215
+	  return '';
1216
+	}
1217
+	$magic_quotes = get_magic_quotes_runtime();
1218
+	set_magic_quotes_runtime(0);
1219
+	$file_buffer = fread($fd, filesize($path));
1220
+	$file_buffer = $this->EncodeString($file_buffer, $encoding);
1221
+	fclose($fd);
1222
+	set_magic_quotes_runtime($magic_quotes);
1223
+
1224
+	return $file_buffer;
1225 1225
   }
1226 1226
 
1227 1227
   /**
@@ -1231,29 +1231,29 @@  discard block
 block discarded – undo
1231 1231
    * @return string
1232 1232
    */
1233 1233
   function EncodeString ($str, $encoding = 'base64') {
1234
-    $encoded = '';
1235
-    switch(strtolower($encoding)) {
1236
-      case 'base64':
1237
-        /* chunk_split is found in PHP >= 3.0.6 */
1238
-        $encoded = chunk_split(base64_encode($str), 76, $this->LE);
1239
-        break;
1240
-      case '7bit':
1241
-      case '8bit':
1242
-        $encoded = $this->FixEOL($str);
1243
-        if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1244
-          $encoded .= $this->LE;
1245
-        break;
1246
-      case 'binary':
1247
-        $encoded = $str;
1248
-        break;
1249
-      case 'quoted-printable':
1250
-        $encoded = $this->EncodeQP($str);
1251
-        break;
1252
-      default:
1253
-        $this->SetError($this->Lang('encoding') . $encoding);
1254
-        break;
1255
-    }
1256
-    return $encoded;
1234
+	$encoded = '';
1235
+	switch(strtolower($encoding)) {
1236
+	  case 'base64':
1237
+		/* chunk_split is found in PHP >= 3.0.6 */
1238
+		$encoded = chunk_split(base64_encode($str), 76, $this->LE);
1239
+		break;
1240
+	  case '7bit':
1241
+	  case '8bit':
1242
+		$encoded = $this->FixEOL($str);
1243
+		if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1244
+		  $encoded .= $this->LE;
1245
+		break;
1246
+	  case 'binary':
1247
+		$encoded = $str;
1248
+		break;
1249
+	  case 'quoted-printable':
1250
+		$encoded = $this->EncodeQP($str);
1251
+		break;
1252
+	  default:
1253
+		$this->SetError($this->Lang('encoding') . $encoding);
1254
+		break;
1255
+	}
1256
+	return $encoded;
1257 1257
   }
1258 1258
 
1259 1259
   /**
@@ -1262,58 +1262,58 @@  discard block
 block discarded – undo
1262 1262
    * @return string
1263 1263
    */
1264 1264
   function EncodeHeader ($str, $position = 'text') {
1265
-    $x = 0;
1266
-
1267
-    switch (strtolower($position)) {
1268
-      case 'phrase':
1269
-        if (!preg_match('/[\200-\377]/', $str)) {
1270
-          /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
1271
-          $encoded = addcslashes($str, "\0..\37\177\\\"");
1272
-          if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
1273
-            return ($encoded);
1274
-          } else {
1275
-            return ("\"$encoded\"");
1276
-          }
1277
-        }
1278
-        $x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
1279
-        break;
1280
-      case 'comment':
1281
-        $x = preg_match_all('/[()"]/', $str, $matches);
1282
-        /* Fall-through */
1283
-      case 'text':
1284
-      default:
1285
-        $x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
1286
-        break;
1287
-    }
1288
-
1289
-    if ($x == 0) {
1290
-      return ($str);
1291
-    }
1292
-
1293
-    $maxlen = 75 - 7 - strlen($this->CharSet);
1294
-    /* Try to select the encoding which should produce the shortest output */
1295
-    if (strlen($str)/3 < $x) {
1296
-      $encoding = 'B';
1297
-      if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
1298
-     // Use a custom function which correctly encodes and wraps long
1299
-     // multibyte strings without breaking lines within a character
1300
-        $encoded = $this->Base64EncodeWrapMB($str);
1301
-      } else {
1302
-        $encoded = base64_encode($str);
1303
-        $maxlen -= $maxlen % 4;
1304
-        $encoded = trim(chunk_split($encoded, $maxlen, "\n"));
1305
-      }
1306
-    } else {
1307
-      $encoding = 'Q';
1308
-      $encoded = $this->EncodeQ($str, $position);
1309
-      $encoded = $this->WrapText($encoded, $maxlen, true);
1310
-      $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
1311
-    }
1312
-
1313
-    $encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
1314
-    $encoded = trim(str_replace("\n", $this->LE, $encoded));
1315
-
1316
-    return $encoded;
1265
+	$x = 0;
1266
+
1267
+	switch (strtolower($position)) {
1268
+	  case 'phrase':
1269
+		if (!preg_match('/[\200-\377]/', $str)) {
1270
+		  /* Can't use addslashes as we don't know what value has magic_quotes_sybase. */
1271
+		  $encoded = addcslashes($str, "\0..\37\177\\\"");
1272
+		  if (($str == $encoded) && !preg_match('/[^A-Za-z0-9!#$%&\'*+\/=?^_`{|}~ -]/', $str)) {
1273
+			return ($encoded);
1274
+		  } else {
1275
+			return ("\"$encoded\"");
1276
+		  }
1277
+		}
1278
+		$x = preg_match_all('/[^\040\041\043-\133\135-\176]/', $str, $matches);
1279
+		break;
1280
+	  case 'comment':
1281
+		$x = preg_match_all('/[()"]/', $str, $matches);
1282
+		/* Fall-through */
1283
+	  case 'text':
1284
+	  default:
1285
+		$x += preg_match_all('/[\000-\010\013\014\016-\037\177-\377]/', $str, $matches);
1286
+		break;
1287
+	}
1288
+
1289
+	if ($x == 0) {
1290
+	  return ($str);
1291
+	}
1292
+
1293
+	$maxlen = 75 - 7 - strlen($this->CharSet);
1294
+	/* Try to select the encoding which should produce the shortest output */
1295
+	if (strlen($str)/3 < $x) {
1296
+	  $encoding = 'B';
1297
+	  if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
1298
+	 // Use a custom function which correctly encodes and wraps long
1299
+	 // multibyte strings without breaking lines within a character
1300
+		$encoded = $this->Base64EncodeWrapMB($str);
1301
+	  } else {
1302
+		$encoded = base64_encode($str);
1303
+		$maxlen -= $maxlen % 4;
1304
+		$encoded = trim(chunk_split($encoded, $maxlen, "\n"));
1305
+	  }
1306
+	} else {
1307
+	  $encoding = 'Q';
1308
+	  $encoded = $this->EncodeQ($str, $position);
1309
+	  $encoded = $this->WrapText($encoded, $maxlen, true);
1310
+	  $encoded = str_replace('='.$this->LE, "\n", trim($encoded));
1311
+	}
1312
+
1313
+	$encoded = preg_replace('/^(.*)$/m', " =?".$this->CharSet."?$encoding?\\1?=", $encoded);
1314
+	$encoded = trim(str_replace("\n", $this->LE, $encoded));
1315
+
1316
+	return $encoded;
1317 1317
   }
1318 1318
 
1319 1319
   /**
@@ -1323,11 +1323,11 @@  discard block
 block discarded – undo
1323 1323
    * @return bool
1324 1324
    */
1325 1325
   function HasMultiBytes($str) {
1326
-    if (function_exists('mb_strlen')) {
1327
-      return (strlen($str) > mb_strlen($str, $this->CharSet));
1328
-    } else { // Assume no multibytes (we can't handle without mbstring functions anyway)
1329
-      return False;
1330
-    }
1326
+	if (function_exists('mb_strlen')) {
1327
+	  return (strlen($str) > mb_strlen($str, $this->CharSet));
1328
+	} else { // Assume no multibytes (we can't handle without mbstring functions anyway)
1329
+	  return False;
1330
+	}
1331 1331
   }
1332 1332
 
1333 1333
   /**
@@ -1339,35 +1339,35 @@  discard block
 block discarded – undo
1339 1339
    * @return string
1340 1340
    */
1341 1341
   function Base64EncodeWrapMB($str) {
1342
-    $start = "=?".$this->CharSet."?B?";
1343
-    $end = "?=";
1344
-    $encoded = "";
1345
-
1346
-    $mb_length = mb_strlen($str, $this->CharSet);
1347
-    // Each line must have length <= 75, including $start and $end
1348
-    $length = 75 - strlen($start) - strlen($end);
1349
-    // Average multi-byte ratio
1350
-    $ratio = $mb_length / strlen($str);
1351
-    // Base64 has a 4:3 ratio
1352
-    $offset = $avgLength = floor($length * $ratio * .75);
1353
-
1354
-    for ($i = 0; $i < $mb_length; $i += $offset) {
1355
-      $lookBack = 0;
1356
-
1357
-      do {
1358
-        $offset = $avgLength - $lookBack;
1359
-        $chunk = mb_substr($str, $i, $offset, $this->CharSet);
1360
-        $chunk = base64_encode($chunk);
1361
-        $lookBack++;
1362
-      }
1363
-      while (strlen($chunk) > $length);
1364
-
1365
-      $encoded .= $chunk . $this->LE;
1366
-    }
1367
-
1368
-    // Chomp the last linefeed
1369
-    $encoded = substr($encoded, 0, -strlen($this->LE));
1370
-    return $encoded;
1342
+	$start = "=?".$this->CharSet."?B?";
1343
+	$end = "?=";
1344
+	$encoded = "";
1345
+
1346
+	$mb_length = mb_strlen($str, $this->CharSet);
1347
+	// Each line must have length <= 75, including $start and $end
1348
+	$length = 75 - strlen($start) - strlen($end);
1349
+	// Average multi-byte ratio
1350
+	$ratio = $mb_length / strlen($str);
1351
+	// Base64 has a 4:3 ratio
1352
+	$offset = $avgLength = floor($length * $ratio * .75);
1353
+
1354
+	for ($i = 0; $i < $mb_length; $i += $offset) {
1355
+	  $lookBack = 0;
1356
+
1357
+	  do {
1358
+		$offset = $avgLength - $lookBack;
1359
+		$chunk = mb_substr($str, $i, $offset, $this->CharSet);
1360
+		$chunk = base64_encode($chunk);
1361
+		$lookBack++;
1362
+	  }
1363
+	  while (strlen($chunk) > $length);
1364
+
1365
+	  $encoded .= $chunk . $this->LE;
1366
+	}
1367
+
1368
+	// Chomp the last linefeed
1369
+	$encoded = substr($encoded, 0, -strlen($this->LE));
1370
+	return $encoded;
1371 1371
   }
1372 1372
 
1373 1373
   /**
@@ -1376,44 +1376,44 @@  discard block
 block discarded – undo
1376 1376
    * @return string
1377 1377
    */
1378 1378
   function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
1379
-    $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
1380
-    $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
1381
-    $eol = "\r\n";
1382
-    $escape = '=';
1383
-    $output = '';
1384
-    while( list(, $line) = each($lines) ) {
1385
-      $linlen = strlen($line);
1386
-      $newline = '';
1387
-      for($i = 0; $i < $linlen; $i++) {
1388
-        $c = substr( $line, $i, 1 );
1389
-        $dec = ord( $c );
1390
-        if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
1391
-          $c = '=2E';
1392
-        }
1393
-        if ( $dec == 32 ) {
1394
-          if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
1395
-            $c = '=20';
1396
-          } else if ( $space_conv ) {
1397
-            $c = '=20';
1398
-          }
1399
-        } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
1400
-          $h2 = floor($dec/16);
1401
-          $h1 = floor($dec%16);
1402
-          $c = $escape.$hex[$h2].$hex[$h1];
1403
-        }
1404
-        if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
1405
-          $output .= $newline.$escape.$eol; //  soft line break; " =\r\n" is okay
1406
-          $newline = '';
1407
-          // check if newline first character will be point or not
1408
-          if ( $dec == 46 ) {
1409
-            $c = '=2E';
1410
-          }
1411
-        }
1412
-        $newline .= $c;
1413
-      } // end of for
1414
-      $output .= $newline.$eol;
1415
-    } // end of while
1416
-    return $output;
1379
+	$hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
1380
+	$lines = preg_split('/(?:\r\n|\r|\n)/', $input);
1381
+	$eol = "\r\n";
1382
+	$escape = '=';
1383
+	$output = '';
1384
+	while( list(, $line) = each($lines) ) {
1385
+	  $linlen = strlen($line);
1386
+	  $newline = '';
1387
+	  for($i = 0; $i < $linlen; $i++) {
1388
+		$c = substr( $line, $i, 1 );
1389
+		$dec = ord( $c );
1390
+		if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
1391
+		  $c = '=2E';
1392
+		}
1393
+		if ( $dec == 32 ) {
1394
+		  if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
1395
+			$c = '=20';
1396
+		  } else if ( $space_conv ) {
1397
+			$c = '=20';
1398
+		  }
1399
+		} elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
1400
+		  $h2 = floor($dec/16);
1401
+		  $h1 = floor($dec%16);
1402
+		  $c = $escape.$hex[$h2].$hex[$h1];
1403
+		}
1404
+		if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
1405
+		  $output .= $newline.$escape.$eol; //  soft line break; " =\r\n" is okay
1406
+		  $newline = '';
1407
+		  // check if newline first character will be point or not
1408
+		  if ( $dec == 46 ) {
1409
+			$c = '=2E';
1410
+		  }
1411
+		}
1412
+		$newline .= $c;
1413
+	  } // end of for
1414
+	  $output .= $newline.$eol;
1415
+	} // end of while
1416
+	return $output;
1417 1417
   }
1418 1418
 
1419 1419
   /**
@@ -1422,27 +1422,27 @@  discard block
 block discarded – undo
1422 1422
    * @return string
1423 1423
    */
1424 1424
   function EncodeQ ($str, $position = 'text') {
1425
-    /* There should not be any EOL in the string */
1426
-    $encoded = preg_replace("[\r\n]", '', $str);
1427
-
1428
-    switch (strtolower($position)) {
1429
-      case 'phrase':
1430
-        $encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1431
-        break;
1432
-      case 'comment':
1433
-        $encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1434
-      case 'text':
1435
-      default:
1436
-        /* Replace every high ascii, control =, ? and _ characters */
1437
-        $encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
1438
-              "'='.sprintf('%02X', ord('\\1'))", $encoded);
1439
-        break;
1440
-    }
1441
-
1442
-    /* Replace every spaces to _ (more readable than =20) */
1443
-    $encoded = str_replace(' ', '_', $encoded);
1444
-
1445
-    return $encoded;
1425
+	/* There should not be any EOL in the string */
1426
+	$encoded = preg_replace("[\r\n]", '', $str);
1427
+
1428
+	switch (strtolower($position)) {
1429
+	  case 'phrase':
1430
+		$encoded = preg_replace("/([^A-Za-z0-9!*+\/ -])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1431
+		break;
1432
+	  case 'comment':
1433
+		$encoded = preg_replace("/([\(\)\"])/e", "'='.sprintf('%02X', ord('\\1'))", $encoded);
1434
+	  case 'text':
1435
+	  default:
1436
+		/* Replace every high ascii, control =, ? and _ characters */
1437
+		$encoded = preg_replace('/([\000-\011\013\014\016-\037\075\077\137\177-\377])/e',
1438
+			  "'='.sprintf('%02X', ord('\\1'))", $encoded);
1439
+		break;
1440
+	}
1441
+
1442
+	/* Replace every spaces to _ (more readable than =20) */
1443
+	$encoded = str_replace(' ', '_', $encoded);
1444
+
1445
+	return $encoded;
1446 1446
   }
1447 1447
 
1448 1448
   /**
@@ -1456,16 +1456,16 @@  discard block
 block discarded – undo
1456 1456
    * @return void
1457 1457
    */
1458 1458
   function AddStringAttachment($string, $filename, $encoding = 'base64', $type = 'application/octet-stream') {
1459
-    /* Append to $attachment array */
1460
-    $cur = count($this->attachment);
1461
-    $this->attachment[$cur][0] = $string;
1462
-    $this->attachment[$cur][1] = $filename;
1463
-    $this->attachment[$cur][2] = $filename;
1464
-    $this->attachment[$cur][3] = $encoding;
1465
-    $this->attachment[$cur][4] = $type;
1466
-    $this->attachment[$cur][5] = true; // isString
1467
-    $this->attachment[$cur][6] = 'attachment';
1468
-    $this->attachment[$cur][7] = 0;
1459
+	/* Append to $attachment array */
1460
+	$cur = count($this->attachment);
1461
+	$this->attachment[$cur][0] = $string;
1462
+	$this->attachment[$cur][1] = $filename;
1463
+	$this->attachment[$cur][2] = $filename;
1464
+	$this->attachment[$cur][3] = $encoding;
1465
+	$this->attachment[$cur][4] = $type;
1466
+	$this->attachment[$cur][5] = true; // isString
1467
+	$this->attachment[$cur][6] = 'attachment';
1468
+	$this->attachment[$cur][7] = 0;
1469 1469
   }
1470 1470
 
1471 1471
   /**
@@ -1483,28 +1483,28 @@  discard block
 block discarded – undo
1483 1483
    */
1484 1484
   function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1485 1485
 
1486
-    if(!@is_file($path)) {
1487
-      $this->SetError($this->Lang('file_access') . $path);
1488
-      return false;
1489
-    }
1490
-
1491
-    $filename = basename($path);
1492
-    if($name == '') {
1493
-      $name = $filename;
1494
-    }
1495
-
1496
-    /* Append to $attachment array */
1497
-    $cur = count($this->attachment);
1498
-    $this->attachment[$cur][0] = $path;
1499
-    $this->attachment[$cur][1] = $filename;
1500
-    $this->attachment[$cur][2] = $name;
1501
-    $this->attachment[$cur][3] = $encoding;
1502
-    $this->attachment[$cur][4] = $type;
1503
-    $this->attachment[$cur][5] = false;
1504
-    $this->attachment[$cur][6] = 'inline';
1505
-    $this->attachment[$cur][7] = $cid;
1506
-
1507
-    return true;
1486
+	if(!@is_file($path)) {
1487
+	  $this->SetError($this->Lang('file_access') . $path);
1488
+	  return false;
1489
+	}
1490
+
1491
+	$filename = basename($path);
1492
+	if($name == '') {
1493
+	  $name = $filename;
1494
+	}
1495
+
1496
+	/* Append to $attachment array */
1497
+	$cur = count($this->attachment);
1498
+	$this->attachment[$cur][0] = $path;
1499
+	$this->attachment[$cur][1] = $filename;
1500
+	$this->attachment[$cur][2] = $name;
1501
+	$this->attachment[$cur][3] = $encoding;
1502
+	$this->attachment[$cur][4] = $type;
1503
+	$this->attachment[$cur][5] = false;
1504
+	$this->attachment[$cur][6] = 'inline';
1505
+	$this->attachment[$cur][7] = $cid;
1506
+
1507
+	return true;
1508 1508
   }
1509 1509
 
1510 1510
   /**
@@ -1513,15 +1513,15 @@  discard block
 block discarded – undo
1513 1513
    * @return bool
1514 1514
    */
1515 1515
   function InlineImageExists() {
1516
-    $result = false;
1517
-    for($i = 0; $i < count($this->attachment); $i++) {
1518
-      if($this->attachment[$i][6] == 'inline') {
1519
-        $result = true;
1520
-        break;
1521
-      }
1522
-    }
1523
-
1524
-    return $result;
1516
+	$result = false;
1517
+	for($i = 0; $i < count($this->attachment); $i++) {
1518
+	  if($this->attachment[$i][6] == 'inline') {
1519
+		$result = true;
1520
+		break;
1521
+	  }
1522
+	}
1523
+
1524
+	return $result;
1525 1525
   }
1526 1526
 
1527 1527
   /////////////////////////////////////////////////
@@ -1533,7 +1533,7 @@  discard block
 block discarded – undo
1533 1533
    * @return void
1534 1534
    */
1535 1535
   function ClearAddresses() {
1536
-    $this->to = array();
1536
+	$this->to = array();
1537 1537
   }
1538 1538
 
1539 1539
   /**
@@ -1541,7 +1541,7 @@  discard block
 block discarded – undo
1541 1541
    * @return void
1542 1542
    */
1543 1543
   function ClearCCs() {
1544
-    $this->cc = array();
1544
+	$this->cc = array();
1545 1545
   }
1546 1546
 
1547 1547
   /**
@@ -1549,7 +1549,7 @@  discard block
 block discarded – undo
1549 1549
    * @return void
1550 1550
    */
1551 1551
   function ClearBCCs() {
1552
-    $this->bcc = array();
1552
+	$this->bcc = array();
1553 1553
   }
1554 1554
 
1555 1555
   /**
@@ -1557,7 +1557,7 @@  discard block
 block discarded – undo
1557 1557
    * @return void
1558 1558
    */
1559 1559
   function ClearReplyTos() {
1560
-    $this->ReplyTo = array();
1560
+	$this->ReplyTo = array();
1561 1561
   }
1562 1562
 
1563 1563
   /**
@@ -1566,9 +1566,9 @@  discard block
 block discarded – undo
1566 1566
    * @return void
1567 1567
    */
1568 1568
   function ClearAllRecipients() {
1569
-    $this->to = array();
1570
-    $this->cc = array();
1571
-    $this->bcc = array();
1569
+	$this->to = array();
1570
+	$this->cc = array();
1571
+	$this->bcc = array();
1572 1572
   }
1573 1573
 
1574 1574
   /**
@@ -1577,7 +1577,7 @@  discard block
 block discarded – undo
1577 1577
    * @return void
1578 1578
    */
1579 1579
   function ClearAttachments() {
1580
-    $this->attachment = array();
1580
+	$this->attachment = array();
1581 1581
   }
1582 1582
 
1583 1583
   /**
@@ -1585,7 +1585,7 @@  discard block
 block discarded – undo
1585 1585
    * @return void
1586 1586
    */
1587 1587
   function ClearCustomHeaders() {
1588
-    $this->CustomHeader = array();
1588
+	$this->CustomHeader = array();
1589 1589
   }
1590 1590
 
1591 1591
   /////////////////////////////////////////////////
@@ -1599,8 +1599,8 @@  discard block
 block discarded – undo
1599 1599
    * @return void
1600 1600
    */
1601 1601
   function SetError($msg) {
1602
-    $this->error_count++;
1603
-    $this->ErrorInfo = $msg;
1602
+	$this->error_count++;
1603
+	$this->ErrorInfo = $msg;
1604 1604
   }
1605 1605
 
1606 1606
   /**
@@ -1609,13 +1609,13 @@  discard block
 block discarded – undo
1609 1609
    * @return string
1610 1610
    */
1611 1611
   function RFCDate() {
1612
-    $tz = date('Z');
1613
-    $tzs = ($tz < 0) ? '-' : '+';
1614
-    $tz = abs($tz);
1615
-    $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
1616
-    $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
1612
+	$tz = date('Z');
1613
+	$tzs = ($tz < 0) ? '-' : '+';
1614
+	$tz = abs($tz);
1615
+	$tz = (int)($tz/3600)*100 + ($tz%3600)/60;
1616
+	$result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
1617 1617
 
1618
-    return $result;
1618
+	return $result;
1619 1619
   }
1620 1620
 
1621 1621
   /**
@@ -1626,21 +1626,21 @@  discard block
 block discarded – undo
1626 1626
    * @return mixed
1627 1627
    */
1628 1628
   function ServerVar($varName) {
1629
-    global $HTTP_SERVER_VARS;
1630
-    global $HTTP_ENV_VARS;
1631
-
1632
-    if(!isset($_SERVER)) {
1633
-      $_SERVER = $HTTP_SERVER_VARS;
1634
-      if(!isset($_SERVER['REMOTE_ADDR'])) {
1635
-        $_SERVER = $HTTP_ENV_VARS; // must be Apache
1636
-      }
1637
-    }
1638
-
1639
-    if(isset($_SERVER[$varName])) {
1640
-      return $_SERVER[$varName];
1641
-    } else {
1642
-      return '';
1643
-    }
1629
+	global $HTTP_SERVER_VARS;
1630
+	global $HTTP_ENV_VARS;
1631
+
1632
+	if(!isset($_SERVER)) {
1633
+	  $_SERVER = $HTTP_SERVER_VARS;
1634
+	  if(!isset($_SERVER['REMOTE_ADDR'])) {
1635
+		$_SERVER = $HTTP_ENV_VARS; // must be Apache
1636
+	  }
1637
+	}
1638
+
1639
+	if(isset($_SERVER[$varName])) {
1640
+	  return $_SERVER[$varName];
1641
+	} else {
1642
+	  return '';
1643
+	}
1644 1644
   }
1645 1645
 
1646 1646
   /**
@@ -1649,15 +1649,15 @@  discard block
 block discarded – undo
1649 1649
    * @return string
1650 1650
    */
1651 1651
   function ServerHostname() {
1652
-    if ($this->Hostname != '') {
1653
-      $result = $this->Hostname;
1654
-    } elseif ($this->ServerVar('SERVER_NAME') != '') {
1655
-      $result = $this->ServerVar('SERVER_NAME');
1656
-    } else {
1657
-      $result = 'localhost.localdomain';
1658
-    }
1659
-
1660
-    return $result;
1652
+	if ($this->Hostname != '') {
1653
+	  $result = $this->Hostname;
1654
+	} elseif ($this->ServerVar('SERVER_NAME') != '') {
1655
+	  $result = $this->ServerVar('SERVER_NAME');
1656
+	} else {
1657
+	  $result = 'localhost.localdomain';
1658
+	}
1659
+
1660
+	return $result;
1661 1661
   }
1662 1662
 
1663 1663
   /**
@@ -1666,15 +1666,15 @@  discard block
 block discarded – undo
1666 1666
    * @return string
1667 1667
    */
1668 1668
   function Lang($key) {
1669
-    if(count($this->language) < 1) {
1670
-      $this->SetLanguage('en'); // set the default language
1671
-    }
1672
-
1673
-    if(isset($this->language[$key])) {
1674
-      return $this->language[$key];
1675
-    } else {
1676
-      return 'Language string failed to load: ' . $key;
1677
-    }
1669
+	if(count($this->language) < 1) {
1670
+	  $this->SetLanguage('en'); // set the default language
1671
+	}
1672
+
1673
+	if(isset($this->language[$key])) {
1674
+	  return $this->language[$key];
1675
+	} else {
1676
+	  return 'Language string failed to load: ' . $key;
1677
+	}
1678 1678
   }
1679 1679
 
1680 1680
   /**
@@ -1682,7 +1682,7 @@  discard block
 block discarded – undo
1682 1682
    * @return bool
1683 1683
    */
1684 1684
   function IsError() {
1685
-    return ($this->error_count > 0);
1685
+	return ($this->error_count > 0);
1686 1686
   }
1687 1687
 
1688 1688
   /**
@@ -1691,10 +1691,10 @@  discard block
 block discarded – undo
1691 1691
    * @return string
1692 1692
    */
1693 1693
   function FixEOL($str) {
1694
-    $str = str_replace("\r\n", "\n", $str);
1695
-    $str = str_replace("\r", "\n", $str);
1696
-    $str = str_replace("\n", $this->LE, $str);
1697
-    return $str;
1694
+	$str = str_replace("\r\n", "\n", $str);
1695
+	$str = str_replace("\r", "\n", $str);
1696
+	$str = str_replace("\n", $this->LE, $str);
1697
+	return $str;
1698 1698
   }
1699 1699
 
1700 1700
   /**
@@ -1702,7 +1702,7 @@  discard block
 block discarded – undo
1702 1702
    * @return void
1703 1703
    */
1704 1704
   function AddCustomHeader($custom_header) {
1705
-    $this->CustomHeader[] = explode(':', $custom_header, 2);
1705
+	$this->CustomHeader[] = explode(':', $custom_header, 2);
1706 1706
   }
1707 1707
 
1708 1708
   /**
@@ -1711,35 +1711,35 @@  discard block
 block discarded – undo
1711 1711
    * @return $message
1712 1712
    */
1713 1713
   function MsgHTML($message,$basedir='') {
1714
-    preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
1715
-    if(isset($images[2])) {
1716
-      foreach($images[2] as $i => $url) {
1717
-        // do not change urls for absolute images (thanks to corvuscorax)
1718
-        if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
1719
-          $filename = basename($url);
1720
-          $directory = dirname($url);
1721
-          ($directory == '.')?$directory='':'';
1722
-          $cid = 'cid:' . md5($filename);
1723
-          $fileParts = split("\.", $filename);
1724
-          $ext = $fileParts[1];
1725
-          $mimeType = $this->_mime_types($ext);
1726
-          if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
1727
-          if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
1728
-          if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
1729
-            $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
1730
-          }
1731
-        }
1732
-      }
1733
-    }
1734
-    $this->IsHTML(true);
1735
-    $this->Body = $message;
1736
-    $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
1737
-    if ( !empty($textMsg) && empty($this->AltBody) ) {
1738
-      $this->AltBody = html_entity_decode($textMsg);
1739
-    }
1740
-    if ( empty($this->AltBody) ) {
1741
-      $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
1742
-    }
1714
+	preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
1715
+	if(isset($images[2])) {
1716
+	  foreach($images[2] as $i => $url) {
1717
+		// do not change urls for absolute images (thanks to corvuscorax)
1718
+		if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
1719
+		  $filename = basename($url);
1720
+		  $directory = dirname($url);
1721
+		  ($directory == '.')?$directory='':'';
1722
+		  $cid = 'cid:' . md5($filename);
1723
+		  $fileParts = split("\.", $filename);
1724
+		  $ext = $fileParts[1];
1725
+		  $mimeType = $this->_mime_types($ext);
1726
+		  if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
1727
+		  if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
1728
+		  if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
1729
+			$message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
1730
+		  }
1731
+		}
1732
+	  }
1733
+	}
1734
+	$this->IsHTML(true);
1735
+	$this->Body = $message;
1736
+	$textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
1737
+	if ( !empty($textMsg) && empty($this->AltBody) ) {
1738
+	  $this->AltBody = html_entity_decode($textMsg);
1739
+	}
1740
+	if ( empty($this->AltBody) ) {
1741
+	  $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
1742
+	}
1743 1743
   }
1744 1744
 
1745 1745
   /**
@@ -1748,95 +1748,95 @@  discard block
 block discarded – undo
1748 1748
    * @return mime type of ext
1749 1749
    */
1750 1750
   function _mime_types($ext = '') {
1751
-    $mimes = array(
1752
-      'ai'    =>  'application/postscript',
1753
-      'aif'   =>  'audio/x-aiff',
1754
-      'aifc'  =>  'audio/x-aiff',
1755
-      'aiff'  =>  'audio/x-aiff',
1756
-      'avi'   =>  'video/x-msvideo',
1757
-      'bin'   =>  'application/macbinary',
1758
-      'bmp'   =>  'image/bmp',
1759
-      'class' =>  'application/octet-stream',
1760
-      'cpt'   =>  'application/mac-compactpro',
1761
-      'css'   =>  'text/css',
1762
-      'dcr'   =>  'application/x-director',
1763
-      'dir'   =>  'application/x-director',
1764
-      'dll'   =>  'application/octet-stream',
1765
-      'dms'   =>  'application/octet-stream',
1766
-      'doc'   =>  'application/msword',
1767
-      'dvi'   =>  'application/x-dvi',
1768
-      'dxr'   =>  'application/x-director',
1769
-      'eml'   =>  'message/rfc822',
1770
-      'eps'   =>  'application/postscript',
1771
-      'exe'   =>  'application/octet-stream',
1772
-      'gif'   =>  'image/gif',
1773
-      'gtar'  =>  'application/x-gtar',
1774
-      'htm'   =>  'text/html',
1775
-      'html'  =>  'text/html',
1776
-      'jpe'   =>  'image/jpeg',
1777
-      'jpeg'  =>  'image/jpeg',
1778
-      'jpg'   =>  'image/jpeg',
1779
-      'hqx'   =>  'application/mac-binhex40',
1780
-      'js'    =>  'application/x-javascript',
1781
-      'lha'   =>  'application/octet-stream',
1782
-      'log'   =>  'text/plain',
1783
-      'lzh'   =>  'application/octet-stream',
1784
-      'mid'   =>  'audio/midi',
1785
-      'midi'  =>  'audio/midi',
1786
-      'mif'   =>  'application/vnd.mif',
1787
-      'mov'   =>  'video/quicktime',
1788
-      'movie' =>  'video/x-sgi-movie',
1789
-      'mp2'   =>  'audio/mpeg',
1790
-      'mp3'   =>  'audio/mpeg',
1791
-      'mpe'   =>  'video/mpeg',
1792
-      'mpeg'  =>  'video/mpeg',
1793
-      'mpg'   =>  'video/mpeg',
1794
-      'mpga'  =>  'audio/mpeg',
1795
-      'oda'   =>  'application/oda',
1796
-      'pdf'   =>  'application/pdf',
1797
-      'php'   =>  'application/x-httpd-php',
1798
-      'php3'  =>  'application/x-httpd-php',
1799
-      'php4'  =>  'application/x-httpd-php',
1800
-      'phps'  =>  'application/x-httpd-php-source',
1801
-      'phtml' =>  'application/x-httpd-php',
1802
-      'png'   =>  'image/png',
1803
-      'ppt'   =>  'application/vnd.ms-powerpoint',
1804
-      'ps'    =>  'application/postscript',
1805
-      'psd'   =>  'application/octet-stream',
1806
-      'qt'    =>  'video/quicktime',
1807
-      'ra'    =>  'audio/x-realaudio',
1808
-      'ram'   =>  'audio/x-pn-realaudio',
1809
-      'rm'    =>  'audio/x-pn-realaudio',
1810
-      'rpm'   =>  'audio/x-pn-realaudio-plugin',
1811
-      'rtf'   =>  'text/rtf',
1812
-      'rtx'   =>  'text/richtext',
1813
-      'rv'    =>  'video/vnd.rn-realvideo',
1814
-      'sea'   =>  'application/octet-stream',
1815
-      'shtml' =>  'text/html',
1816
-      'sit'   =>  'application/x-stuffit',
1817
-      'so'    =>  'application/octet-stream',
1818
-      'smi'   =>  'application/smil',
1819
-      'smil'  =>  'application/smil',
1820
-      'swf'   =>  'application/x-shockwave-flash',
1821
-      'tar'   =>  'application/x-tar',
1822
-      'text'  =>  'text/plain',
1823
-      'txt'   =>  'text/plain',
1824
-      'tgz'   =>  'application/x-tar',
1825
-      'tif'   =>  'image/tiff',
1826
-      'tiff'  =>  'image/tiff',
1827
-      'wav'   =>  'audio/x-wav',
1828
-      'wbxml' =>  'application/vnd.wap.wbxml',
1829
-      'wmlc'  =>  'application/vnd.wap.wmlc',
1830
-      'word'  =>  'application/msword',
1831
-      'xht'   =>  'application/xhtml+xml',
1832
-      'xhtml' =>  'application/xhtml+xml',
1833
-      'xl'    =>  'application/excel',
1834
-      'xls'   =>  'application/vnd.ms-excel',
1835
-      'xml'   =>  'text/xml',
1836
-      'xsl'   =>  'text/xml',
1837
-      'zip'   =>  'application/zip'
1838
-    );
1839
-    return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
1751
+	$mimes = array(
1752
+	  'ai'    =>  'application/postscript',
1753
+	  'aif'   =>  'audio/x-aiff',
1754
+	  'aifc'  =>  'audio/x-aiff',
1755
+	  'aiff'  =>  'audio/x-aiff',
1756
+	  'avi'   =>  'video/x-msvideo',
1757
+	  'bin'   =>  'application/macbinary',
1758
+	  'bmp'   =>  'image/bmp',
1759
+	  'class' =>  'application/octet-stream',
1760
+	  'cpt'   =>  'application/mac-compactpro',
1761
+	  'css'   =>  'text/css',
1762
+	  'dcr'   =>  'application/x-director',
1763
+	  'dir'   =>  'application/x-director',
1764
+	  'dll'   =>  'application/octet-stream',
1765
+	  'dms'   =>  'application/octet-stream',
1766
+	  'doc'   =>  'application/msword',
1767
+	  'dvi'   =>  'application/x-dvi',
1768
+	  'dxr'   =>  'application/x-director',
1769
+	  'eml'   =>  'message/rfc822',
1770
+	  'eps'   =>  'application/postscript',
1771
+	  'exe'   =>  'application/octet-stream',
1772
+	  'gif'   =>  'image/gif',
1773
+	  'gtar'  =>  'application/x-gtar',
1774
+	  'htm'   =>  'text/html',
1775
+	  'html'  =>  'text/html',
1776
+	  'jpe'   =>  'image/jpeg',
1777
+	  'jpeg'  =>  'image/jpeg',
1778
+	  'jpg'   =>  'image/jpeg',
1779
+	  'hqx'   =>  'application/mac-binhex40',
1780
+	  'js'    =>  'application/x-javascript',
1781
+	  'lha'   =>  'application/octet-stream',
1782
+	  'log'   =>  'text/plain',
1783
+	  'lzh'   =>  'application/octet-stream',
1784
+	  'mid'   =>  'audio/midi',
1785
+	  'midi'  =>  'audio/midi',
1786
+	  'mif'   =>  'application/vnd.mif',
1787
+	  'mov'   =>  'video/quicktime',
1788
+	  'movie' =>  'video/x-sgi-movie',
1789
+	  'mp2'   =>  'audio/mpeg',
1790
+	  'mp3'   =>  'audio/mpeg',
1791
+	  'mpe'   =>  'video/mpeg',
1792
+	  'mpeg'  =>  'video/mpeg',
1793
+	  'mpg'   =>  'video/mpeg',
1794
+	  'mpga'  =>  'audio/mpeg',
1795
+	  'oda'   =>  'application/oda',
1796
+	  'pdf'   =>  'application/pdf',
1797
+	  'php'   =>  'application/x-httpd-php',
1798
+	  'php3'  =>  'application/x-httpd-php',
1799
+	  'php4'  =>  'application/x-httpd-php',
1800
+	  'phps'  =>  'application/x-httpd-php-source',
1801
+	  'phtml' =>  'application/x-httpd-php',
1802
+	  'png'   =>  'image/png',
1803
+	  'ppt'   =>  'application/vnd.ms-powerpoint',
1804
+	  'ps'    =>  'application/postscript',
1805
+	  'psd'   =>  'application/octet-stream',
1806
+	  'qt'    =>  'video/quicktime',
1807
+	  'ra'    =>  'audio/x-realaudio',
1808
+	  'ram'   =>  'audio/x-pn-realaudio',
1809
+	  'rm'    =>  'audio/x-pn-realaudio',
1810
+	  'rpm'   =>  'audio/x-pn-realaudio-plugin',
1811
+	  'rtf'   =>  'text/rtf',
1812
+	  'rtx'   =>  'text/richtext',
1813
+	  'rv'    =>  'video/vnd.rn-realvideo',
1814
+	  'sea'   =>  'application/octet-stream',
1815
+	  'shtml' =>  'text/html',
1816
+	  'sit'   =>  'application/x-stuffit',
1817
+	  'so'    =>  'application/octet-stream',
1818
+	  'smi'   =>  'application/smil',
1819
+	  'smil'  =>  'application/smil',
1820
+	  'swf'   =>  'application/x-shockwave-flash',
1821
+	  'tar'   =>  'application/x-tar',
1822
+	  'text'  =>  'text/plain',
1823
+	  'txt'   =>  'text/plain',
1824
+	  'tgz'   =>  'application/x-tar',
1825
+	  'tif'   =>  'image/tiff',
1826
+	  'tiff'  =>  'image/tiff',
1827
+	  'wav'   =>  'audio/x-wav',
1828
+	  'wbxml' =>  'application/vnd.wap.wbxml',
1829
+	  'wmlc'  =>  'application/vnd.wap.wmlc',
1830
+	  'word'  =>  'application/msword',
1831
+	  'xht'   =>  'application/xhtml+xml',
1832
+	  'xhtml' =>  'application/xhtml+xml',
1833
+	  'xl'    =>  'application/excel',
1834
+	  'xls'   =>  'application/vnd.ms-excel',
1835
+	  'xml'   =>  'text/xml',
1836
+	  'xsl'   =>  'text/xml',
1837
+	  'zip'   =>  'application/zip'
1838
+	);
1839
+	return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
1840 1840
   }
1841 1841
 
1842 1842
   /**
@@ -1851,12 +1851,12 @@  discard block
 block discarded – undo
1851 1851
    * NOTE: will not work with arrays, there are no arrays to set/reset
1852 1852
    */
1853 1853
   function set ( $name, $value = '' ) {
1854
-    if ( isset($this->$name) ) {
1855
-      $this->$name = $value;
1856
-    } else {
1857
-      $this->SetError('Cannot set or reset variable ' . $name);
1858
-      return false;
1859
-    }
1854
+	if ( isset($this->$name) ) {
1855
+	  $this->$name = $value;
1856
+	} else {
1857
+	  $this->SetError('Cannot set or reset variable ' . $name);
1858
+	  return false;
1859
+	}
1860 1860
   }
1861 1861
 
1862 1862
   /**
@@ -1866,16 +1866,16 @@  discard block
 block discarded – undo
1866 1866
    * @param string $filename Parameter File Name
1867 1867
    */
1868 1868
   function getFile($filename) {
1869
-    $return = '';
1870
-    if ($fp = fopen($filename, 'rb')) {
1871
-      while (!feof($fp)) {
1872
-        $return .= fread($fp, 1024);
1873
-      }
1874
-      fclose($fp);
1875
-      return $return;
1876
-    } else {
1877
-      return false;
1878
-    }
1869
+	$return = '';
1870
+	if ($fp = fopen($filename, 'rb')) {
1871
+	  while (!feof($fp)) {
1872
+		$return .= fread($fp, 1024);
1873
+	  }
1874
+	  fclose($fp);
1875
+	  return $return;
1876
+	} else {
1877
+	  return false;
1878
+	}
1879 1879
   }
1880 1880
 
1881 1881
   /**
@@ -1885,10 +1885,10 @@  discard block
 block discarded – undo
1885 1885
    * @return string
1886 1886
    */
1887 1887
   function SecureHeader($str) {
1888
-    $str = trim($str);
1889
-    $str = str_replace("\r", "", $str);
1890
-    $str = str_replace("\n", "", $str);
1891
-    return $str;
1888
+	$str = trim($str);
1889
+	$str = str_replace("\r", "", $str);
1890
+	$str = str_replace("\n", "", $str);
1891
+	return $str;
1892 1892
   }
1893 1893
 
1894 1894
   /**
@@ -1899,9 +1899,9 @@  discard block
 block discarded – undo
1899 1899
    * @param string $key_pass Password for private key
1900 1900
    */
1901 1901
   function Sign($cert_filename, $key_filename, $key_pass) {
1902
-    $this->sign_cert_file = $cert_filename;
1903
-    $this->sign_key_file = $key_filename;
1904
-    $this->sign_key_pass = $key_pass;
1902
+	$this->sign_cert_file = $cert_filename;
1903
+	$this->sign_key_file = $key_filename;
1904
+	$this->sign_key_pass = $key_pass;
1905 1905
   }
1906 1906
 
1907 1907
 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1240,8 +1240,9 @@
 block discarded – undo
1240 1240
       case '7bit':
1241 1241
       case '8bit':
1242 1242
         $encoded = $this->FixEOL($str);
1243
-        if (substr($encoded, -(strlen($this->LE))) != $this->LE)
1244
-          $encoded .= $this->LE;
1243
+        if (substr($encoded, -(strlen($this->LE))) != $this->LE) {
1244
+                  $encoded .= $this->LE;
1245
+        }
1245 1246
         break;
1246 1247
       case 'binary':
1247 1248
         $encoded = $str;
Please login to merge, or discard this patch.
Spacing   +185 added lines, -186 removed lines patch added patch discarded remove patch
@@ -41,64 +41,64 @@  discard block
 block discarded – undo
41 41
    * Email priority (1 = High, 3 = Normal, 5 = low).
42 42
    * @var int
43 43
    */
44
-  var $Priority          = 3;
44
+  var $Priority = 3;
45 45
 
46 46
   /**
47 47
    * Sets the CharSet of the message.
48 48
    * @var string
49 49
    */
50
-  var $CharSet           = 'iso-8859-1';
50
+  var $CharSet = 'iso-8859-1';
51 51
 
52 52
   /**
53 53
    * Sets the Content-type of the message.
54 54
    * @var string
55 55
    */
56
-  var $ContentType        = 'text/plain';
56
+  var $ContentType = 'text/plain';
57 57
 
58 58
   /**
59 59
    * Sets the Encoding of the message. Options for this are "8bit",
60 60
    * "7bit", "binary", "base64", and "quoted-printable".
61 61
    * @var string
62 62
    */
63
-  var $Encoding          = '8bit';
63
+  var $Encoding = '8bit';
64 64
 
65 65
   /**
66 66
    * Holds the most recent mailer error message.
67 67
    * @var string
68 68
    */
69
-  var $ErrorInfo         = '';
69
+  var $ErrorInfo = '';
70 70
 
71 71
   /**
72 72
    * Sets the From email address for the message.
73 73
    * @var string
74 74
    */
75
-  var $From              = 'root@localhost';
75
+  var $From = 'root@localhost';
76 76
 
77 77
   /**
78 78
    * Sets the From name of the message.
79 79
    * @var string
80 80
    */
81
-  var $FromName          = 'Root User';
81
+  var $FromName = 'Root User';
82 82
 
83 83
   /**
84 84
    * Sets the Sender email (Return-Path) of the message.  If not empty,
85 85
    * will be sent via -f to sendmail or as 'MAIL FROM' in smtp mode.
86 86
    * @var string
87 87
    */
88
-  var $Sender            = '';
88
+  var $Sender = '';
89 89
 
90 90
   /**
91 91
    * Sets the Subject of the message.
92 92
    * @var string
93 93
    */
94
-  var $Subject           = '';
94
+  var $Subject = '';
95 95
 
96 96
   /**
97 97
    * Sets the Body of the message.  This can be either an HTML or text body.
98 98
    * If HTML then run IsHTML(true).
99 99
    * @var string
100 100
    */
101
-  var $Body              = '';
101
+  var $Body = '';
102 102
 
103 103
   /**
104 104
    * Sets the text-only body of the message.  This automatically sets the
@@ -107,45 +107,45 @@  discard block
 block discarded – undo
107 107
    * that can read HTML will view the normal Body.
108 108
    * @var string
109 109
    */
110
-  var $AltBody           = '';
110
+  var $AltBody = '';
111 111
 
112 112
   /**
113 113
    * Sets word wrapping on the body of the message to a given number of
114 114
    * characters.
115 115
    * @var int
116 116
    */
117
-  var $WordWrap          = 0;
117
+  var $WordWrap = 0;
118 118
 
119 119
   /**
120 120
    * Method to send mail: ("mail", "sendmail", or "smtp").
121 121
    * @var string
122 122
    */
123
-  var $Mailer            = 'mail';
123
+  var $Mailer = 'mail';
124 124
 
125 125
   /**
126 126
    * Sets the path of the sendmail program.
127 127
    * @var string
128 128
    */
129
-  var $Sendmail          = '/usr/sbin/sendmail';
129
+  var $Sendmail = '/usr/sbin/sendmail';
130 130
 
131 131
   /**
132 132
    * Path to PHPMailer plugins.  This is now only useful if the SMTP class
133 133
    * is in a different directory than the PHP include path.
134 134
    * @var string
135 135
    */
136
-  var $PluginDir         = '';
136
+  var $PluginDir = '';
137 137
 
138 138
   /**
139 139
    * Holds PHPMailer version.
140 140
    * @var string
141 141
    */
142
-  var $Version           = "2.0.4";
142
+  var $Version = "2.0.4";
143 143
 
144 144
   /**
145 145
    * Sets the email address that a reading confirmation will be sent.
146 146
    * @var string
147 147
    */
148
-  var $ConfirmReadingTo  = '';
148
+  var $ConfirmReadingTo = '';
149 149
 
150 150
   /**
151 151
    * Sets the hostname to use in Message-Id and Received headers
@@ -153,14 +153,14 @@  discard block
 block discarded – undo
153 153
    * by SERVER_NAME is used or 'localhost.localdomain'.
154 154
    * @var string
155 155
    */
156
-  var $Hostname          = '';
156
+  var $Hostname = '';
157 157
 
158 158
   /**
159 159
    * Sets the message ID to be used in the Message-Id header.
160 160
    * If empty, a unique id will be generated.
161 161
    * @var string
162 162
    */
163
-  var $MessageID         = '';
163
+  var $MessageID = '';
164 164
 
165 165
   /////////////////////////////////////////////////
166 166
   // PROPERTIES FOR SMTP
@@ -174,19 +174,19 @@  discard block
 block discarded – undo
174 174
    * Hosts will be tried in order.
175 175
    * @var string
176 176
    */
177
-  var $Host        = 'localhost';
177
+  var $Host = 'localhost';
178 178
 
179 179
   /**
180 180
    * Sets the default SMTP server port.
181 181
    * @var int
182 182
    */
183
-  var $Port        = 25;
183
+  var $Port = 25;
184 184
 
185 185
   /**
186 186
    * Sets the SMTP HELO of the message (Default is $Hostname).
187 187
    * @var string
188 188
    */
189
-  var $Helo        = '';
189
+  var $Helo = '';
190 190
 
191 191
   /**
192 192
    * Sets connection prefix.
@@ -199,32 +199,32 @@  discard block
 block discarded – undo
199 199
    * Sets SMTP authentication. Utilizes the Username and Password variables.
200 200
    * @var bool
201 201
    */
202
-  var $SMTPAuth     = false;
202
+  var $SMTPAuth = false;
203 203
 
204 204
   /**
205 205
    * Sets SMTP username.
206 206
    * @var string
207 207
    */
208
-  var $Username     = '';
208
+  var $Username = '';
209 209
 
210 210
   /**
211 211
    * Sets SMTP password.
212 212
    * @var string
213 213
    */
214
-  var $Password     = '';
214
+  var $Password = '';
215 215
 
216 216
   /**
217 217
    * Sets the SMTP server timeout in seconds. This function will not
218 218
    * work with the win32 version.
219 219
    * @var int
220 220
    */
221
-  var $Timeout      = 10;
221
+  var $Timeout = 10;
222 222
 
223 223
   /**
224 224
    * Sets SMTP class debugging on or off.
225 225
    * @var bool
226 226
    */
227
-  var $SMTPDebug    = false;
227
+  var $SMTPDebug = false;
228 228
 
229 229
   /**
230 230
    * Prevents the SMTP connection from being closed after each mail
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
    * @return void
272 272
    */
273 273
   function IsHTML($bool) {
274
-    if($bool == true) {
274
+    if ($bool == true) {
275 275
       $this->ContentType = 'text/html';
276 276
     } else {
277 277
       $this->ContentType = 'text/plain';
@@ -382,13 +382,13 @@  discard block
 block discarded – undo
382 382
     $body = '';
383 383
     $result = true;
384 384
 
385
-    if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
385
+    if ((count($this->to) + count($this->cc) + count($this->bcc)) < 1) {
386 386
       $this->SetError($this->Lang('provide_address'));
387 387
       return false;
388 388
     }
389 389
 
390 390
     /* Set whether the message is multipart/alternative */
391
-    if(!empty($this->AltBody)) {
391
+    if (!empty($this->AltBody)) {
392 392
       $this->ContentType = 'multipart/alternative';
393 393
     }
394 394
 
@@ -397,12 +397,12 @@  discard block
 block discarded – undo
397 397
     $header .= $this->CreateHeader();
398 398
     $body = $this->CreateBody();
399 399
 
400
-    if($body == '') {
400
+    if ($body == '') {
401 401
       return false;
402 402
     }
403 403
 
404 404
     /* Choose the mailer */
405
-    switch($this->Mailer) {
405
+    switch ($this->Mailer) {
406 406
       case 'sendmail':
407 407
         $result = $this->SendmailSend($header, $body);
408 408
         break;
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
       $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail));
436 436
     }
437 437
 
438
-    if(!@$mail = popen($sendmail, 'w')) {
439
-      $this->SetError($this->Lang('execute') . $this->Sendmail);
438
+    if (!@$mail = popen($sendmail, 'w')) {
439
+      $this->SetError($this->Lang('execute').$this->Sendmail);
440 440
       return false;
441 441
     }
442 442
 
@@ -447,8 +447,8 @@  discard block
 block discarded – undo
447 447
     if (version_compare(phpversion(), '4.2.3') == -1) {
448 448
       $result = $result >> 8 & 0xFF;
449 449
     }
450
-    if($result != 0) {
451
-      $this->SetError($this->Lang('execute') . $this->Sendmail);
450
+    if ($result != 0) {
451
+      $this->SetError($this->Lang('execute').$this->Sendmail);
452 452
       return false;
453 453
     }
454 454
     return true;
@@ -462,8 +462,8 @@  discard block
 block discarded – undo
462 462
   function MailSend($header, $body) {
463 463
 
464 464
     $to = '';
465
-    for($i = 0; $i < count($this->to); $i++) {
466
-      if($i != 0) { $to .= ', '; }
465
+    for ($i = 0; $i < count($this->to); $i++) {
466
+      if ($i != 0) { $to .= ', '; }
467 467
       $to .= $this->AddrFormat($this->to[$i]);
468 468
     }
469 469
 
@@ -494,7 +494,7 @@  discard block
 block discarded – undo
494 494
       ini_set('sendmail_from', $old_from);
495 495
     }
496 496
 
497
-    if(!$rt) {
497
+    if (!$rt) {
498 498
       $this->SetError($this->Lang('instantiate'));
499 499
       return false;
500 500
     }
@@ -510,58 +510,58 @@  discard block
 block discarded – undo
510 510
    * @return bool
511 511
    */
512 512
   function SmtpSend($header, $body) {
513
-    include_once($this->PluginDir . 'class.smtp.php');
513
+    include_once($this->PluginDir.'class.smtp.php');
514 514
     $error = '';
515 515
     $bad_rcpt = array();
516 516
 
517
-    if(!$this->SmtpConnect()) {
517
+    if (!$this->SmtpConnect()) {
518 518
       return false;
519 519
     }
520 520
 
521 521
     $smtp_from = ($this->Sender == '') ? $this->From : $this->Sender;
522
-    if(!$this->smtp->Mail($smtp_from)) {
523
-      $error = $this->Lang('from_failed') . $smtp_from;
522
+    if (!$this->smtp->Mail($smtp_from)) {
523
+      $error = $this->Lang('from_failed').$smtp_from;
524 524
       $this->SetError($error);
525 525
       $this->smtp->Reset();
526 526
       return false;
527 527
     }
528 528
 
529 529
     /* Attempt to send attach all recipients */
530
-    for($i = 0; $i < count($this->to); $i++) {
531
-      if(!$this->smtp->Recipient($this->to[$i][0])) {
530
+    for ($i = 0; $i < count($this->to); $i++) {
531
+      if (!$this->smtp->Recipient($this->to[$i][0])) {
532 532
         $bad_rcpt[] = $this->to[$i][0];
533 533
       }
534 534
     }
535
-    for($i = 0; $i < count($this->cc); $i++) {
536
-      if(!$this->smtp->Recipient($this->cc[$i][0])) {
535
+    for ($i = 0; $i < count($this->cc); $i++) {
536
+      if (!$this->smtp->Recipient($this->cc[$i][0])) {
537 537
         $bad_rcpt[] = $this->cc[$i][0];
538 538
       }
539 539
     }
540
-    for($i = 0; $i < count($this->bcc); $i++) {
541
-      if(!$this->smtp->Recipient($this->bcc[$i][0])) {
540
+    for ($i = 0; $i < count($this->bcc); $i++) {
541
+      if (!$this->smtp->Recipient($this->bcc[$i][0])) {
542 542
         $bad_rcpt[] = $this->bcc[$i][0];
543 543
       }
544 544
     }
545 545
 
546
-    if(count($bad_rcpt) > 0) { // Create error message
547
-      for($i = 0; $i < count($bad_rcpt); $i++) {
548
-        if($i != 0) {
546
+    if (count($bad_rcpt) > 0) { // Create error message
547
+      for ($i = 0; $i < count($bad_rcpt); $i++) {
548
+        if ($i != 0) {
549 549
           $error .= ', ';
550 550
         }
551 551
         $error .= $bad_rcpt[$i];
552 552
       }
553
-      $error = $this->Lang('recipients_failed') . $error;
553
+      $error = $this->Lang('recipients_failed').$error;
554 554
       $this->SetError($error);
555 555
       $this->smtp->Reset();
556 556
       return false;
557 557
     }
558 558
 
559
-    if(!$this->smtp->Data($header . $body)) {
559
+    if (!$this->smtp->Data($header.$body)) {
560 560
       $this->SetError($this->Lang('data_not_accepted'));
561 561
       $this->smtp->Reset();
562 562
       return false;
563 563
     }
564
-    if($this->SMTPKeepAlive == true) {
564
+    if ($this->SMTPKeepAlive == true) {
565 565
       $this->smtp->Reset();
566 566
     } else {
567 567
       $this->SmtpClose();
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
    * @return bool
578 578
    */
579 579
   function SmtpConnect() {
580
-    if($this->smtp == NULL) {
580
+    if ($this->smtp == NULL) {
581 581
       $this->smtp = new SMTP();
582 582
     }
583 583
 
@@ -587,9 +587,9 @@  discard block
 block discarded – undo
587 587
     $connection = ($this->smtp->Connected());
588 588
 
589 589
     /* Retry while there is no connection */
590
-    while($index < count($hosts) && $connection == false) {
590
+    while ($index < count($hosts) && $connection == false) {
591 591
       $hostinfo = array();
592
-      if(eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
592
+      if (eregi('^(.+):([0-9]+)$', $hosts[$index], $hostinfo)) {
593 593
         $host = $hostinfo[1];
594 594
         $port = $hostinfo[2];
595 595
       } else {
@@ -597,7 +597,7 @@  discard block
 block discarded – undo
597 597
         $port = $this->Port;
598 598
       }
599 599
 
600
-      if($this->smtp->Connect(((!empty($this->SMTPSecure))?$this->SMTPSecure.'://':'').$host, $port, $this->Timeout)) {
600
+      if ($this->smtp->Connect(((!empty($this->SMTPSecure)) ? $this->SMTPSecure.'://' : '').$host, $port, $this->Timeout)) {
601 601
         if ($this->Helo != '') {
602 602
           $this->smtp->Hello($this->Helo);
603 603
         } else {
@@ -605,8 +605,8 @@  discard block
 block discarded – undo
605 605
         }
606 606
 
607 607
         $connection = true;
608
-        if($this->SMTPAuth) {
609
-          if(!$this->smtp->Authenticate($this->Username, $this->Password)) {
608
+        if ($this->SMTPAuth) {
609
+          if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
610 610
             $this->SetError($this->Lang('authenticate'));
611 611
             $this->smtp->Reset();
612 612
             $connection = false;
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
       }
616 616
       $index++;
617 617
     }
618
-    if(!$connection) {
618
+    if (!$connection) {
619 619
       $this->SetError($this->Lang('connect_host'));
620 620
     }
621 621
 
@@ -627,8 +627,8 @@  discard block
 block discarded – undo
627 627
    * @return void
628 628
    */
629 629
   function SmtpClose() {
630
-    if($this->smtp != NULL) {
631
-      if($this->smtp->Connected()) {
630
+    if ($this->smtp != NULL) {
631
+      if ($this->smtp->Connected()) {
632 632
         $this->smtp->Quit();
633 633
         $this->smtp->Close();
634 634
       }
@@ -645,19 +645,19 @@  discard block
 block discarded – undo
645 645
    * @return bool
646 646
    */
647 647
   function SetLanguage($lang_type, $lang_path = 'language/') {
648
-    if(file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
648
+    if (file_exists($lang_path.'phpmailer.lang-'.$lang_type.'.php')) {
649 649
       include($lang_path.'phpmailer.lang-'.$lang_type.'.php');
650 650
     } elseif (file_exists($lang_path.'phpmailer.lang-en.php')) {
651 651
       include($lang_path.'phpmailer.lang-en.php');
652 652
     } else {
653 653
       $PHPMAILER_LANG = array();
654
-      $PHPMAILER_LANG["provide_address"]      = 'You must provide at least one ' .
654
+      $PHPMAILER_LANG["provide_address"]      = 'You must provide at least one '.
655 655
       $PHPMAILER_LANG["mailer_not_supported"] = ' mailer is not supported.';
656 656
       $PHPMAILER_LANG["execute"]              = 'Could not execute: ';
657 657
       $PHPMAILER_LANG["instantiate"]          = 'Could not instantiate mail function.';
658 658
       $PHPMAILER_LANG["authenticate"]         = 'SMTP Error: Could not authenticate.';
659 659
       $PHPMAILER_LANG["from_failed"]          = 'The following From address failed: ';
660
-      $PHPMAILER_LANG["recipients_failed"]    = 'SMTP Error: The following ' .
660
+      $PHPMAILER_LANG["recipients_failed"]    = 'SMTP Error: The following '.
661 661
       $PHPMAILER_LANG["data_not_accepted"]    = 'SMTP Error: Data not accepted.';
662 662
       $PHPMAILER_LANG["connect_host"]         = 'SMTP Error: Could not connect to SMTP host.';
663 663
       $PHPMAILER_LANG["file_access"]          = 'Could not access file: ';
@@ -680,11 +680,11 @@  discard block
 block discarded – undo
680 680
    * @return string
681 681
    */
682 682
   function AddrAppend($type, $addr) {
683
-    $addr_str = $type . ': ';
683
+    $addr_str = $type.': ';
684 684
     $addr_str .= $this->AddrFormat($addr[0]);
685
-    if(count($addr) > 1) {
686
-      for($i = 1; $i < count($addr); $i++) {
687
-        $addr_str .= ', ' . $this->AddrFormat($addr[$i]);
685
+    if (count($addr) > 1) {
686
+      for ($i = 1; $i < count($addr); $i++) {
687
+        $addr_str .= ', '.$this->AddrFormat($addr[$i]);
688 688
       }
689 689
     }
690 690
     $addr_str .= $this->LE;
@@ -698,10 +698,10 @@  discard block
 block discarded – undo
698 698
    * @return string
699 699
    */
700 700
   function AddrFormat($addr) {
701
-    if(empty($addr[1])) {
701
+    if (empty($addr[1])) {
702 702
       $formatted = $this->SecureHeader($addr[0]);
703 703
     } else {
704
-      $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase') . " <" . $this->SecureHeader($addr[0]) . ">";
704
+      $formatted = $this->EncodeHeader($this->SecureHeader($addr[1]), 'phrase')." <".$this->SecureHeader($addr[0]).">";
705 705
     }
706 706
 
707 707
     return $formatted;
@@ -727,10 +727,10 @@  discard block
 block discarded – undo
727 727
 
728 728
     $line = explode($this->LE, $message);
729 729
     $message = '';
730
-    for ($i=0 ;$i < count($line); $i++) {
730
+    for ($i = 0; $i < count($line); $i++) {
731 731
       $line_part = explode(' ', $line[$i]);
732 732
       $buf = '';
733
-      for ($e = 0; $e<count($line_part); $e++) {
733
+      for ($e = 0; $e < count($line_part); $e++) {
734 734
         $word = $line_part[$e];
735 735
         if ($qp_mode and (strlen($word) > $length)) {
736 736
           $space_left = $length - strlen($buf) - 1;
@@ -746,10 +746,10 @@  discard block
 block discarded – undo
746 746
               }
747 747
               $part = substr($word, 0, $len);
748 748
               $word = substr($word, $len);
749
-              $buf .= ' ' . $part;
750
-              $message .= $buf . sprintf("=%s", $this->LE);
749
+              $buf .= ' '.$part;
750
+              $message .= $buf.sprintf("=%s", $this->LE);
751 751
             } else {
752
-              $message .= $buf . $soft_break;
752
+              $message .= $buf.$soft_break;
753 753
             }
754 754
             $buf = '';
755 755
           }
@@ -766,22 +766,22 @@  discard block
 block discarded – undo
766 766
             $word = substr($word, $len);
767 767
 
768 768
             if (strlen($word) > 0) {
769
-              $message .= $part . sprintf("=%s", $this->LE);
769
+              $message .= $part.sprintf("=%s", $this->LE);
770 770
             } else {
771 771
               $buf = $part;
772 772
             }
773 773
           }
774 774
         } else {
775 775
           $buf_o = $buf;
776
-          $buf .= ($e == 0) ? $word : (' ' . $word);
776
+          $buf .= ($e == 0) ? $word : (' '.$word);
777 777
 
778 778
           if (strlen($buf) > $length and $buf_o != '') {
779
-            $message .= $buf_o . $soft_break;
779
+            $message .= $buf_o.$soft_break;
780 780
             $buf = $word;
781 781
           }
782 782
         }
783 783
       }
784
-      $message .= $buf . $this->LE;
784
+      $message .= $buf.$this->LE;
785 785
     }
786 786
 
787 787
     return $message;
@@ -810,8 +810,7 @@  discard block
 block discarded – undo
810 810
         if ($dec < 128) { // Single byte character.
811 811
           // If the encoded char was found at pos 0, it will fit
812 812
           // otherwise reduce maxLength to start of the encoded char
813
-          $maxLength = ($encodedCharPos == 0) ? $maxLength :
814
-          $maxLength - ($lookBack - $encodedCharPos);
813
+          $maxLength = ($encodedCharPos == 0) ? $maxLength : $maxLength - ($lookBack - $encodedCharPos);
815 814
           $foundSplitPos = true;
816 815
         } elseif ($dec >= 192) { // First byte of a multi byte character
817 816
           // Reduce maxLength to split at start of character
@@ -834,11 +833,11 @@  discard block
 block discarded – undo
834 833
    * @return void
835 834
    */
836 835
   function SetWordWrap() {
837
-    if($this->WordWrap < 1) {
836
+    if ($this->WordWrap < 1) {
838 837
       return;
839 838
     }
840 839
 
841
-    switch($this->message_type) {
840
+    switch ($this->message_type) {
842 841
       case 'alt':
843 842
         /* fall through */
844 843
       case 'alt_attachments':
@@ -860,19 +859,19 @@  discard block
 block discarded – undo
860 859
 
861 860
     /* Set the boundaries */
862 861
     $uniq_id = md5(uniqid(time()));
863
-    $this->boundary[1] = 'b1_' . $uniq_id;
864
-    $this->boundary[2] = 'b2_' . $uniq_id;
862
+    $this->boundary[1] = 'b1_'.$uniq_id;
863
+    $this->boundary[2] = 'b2_'.$uniq_id;
865 864
 
866 865
     $result .= $this->HeaderLine('Date', $this->RFCDate());
867
-    if($this->Sender == '') {
866
+    if ($this->Sender == '') {
868 867
       $result .= $this->HeaderLine('Return-Path', trim($this->From));
869 868
     } else {
870 869
       $result .= $this->HeaderLine('Return-Path', trim($this->Sender));
871 870
     }
872 871
 
873 872
     /* To be created automatically by mail() */
874
-    if($this->Mailer != 'mail') {
875
-      if(count($this->to) > 0) {
873
+    if ($this->Mailer != 'mail') {
874
+      if (count($this->to) > 0) {
876 875
         $result .= $this->AddrAppend('To', $this->to);
877 876
       } elseif (count($this->cc) == 0) {
878 877
         $result .= $this->HeaderLine('To', 'undisclosed-recipients:;');
@@ -885,38 +884,38 @@  discard block
 block discarded – undo
885 884
     $result .= $this->AddrAppend('From', $from);
886 885
 
887 886
     /* sendmail and mail() extract Cc from the header before sending */
888
-    if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
887
+    if ((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->cc) > 0)) {
889 888
       $result .= $this->AddrAppend('Cc', $this->cc);
890 889
     }
891 890
 
892 891
     /* sendmail and mail() extract Bcc from the header before sending */
893
-    if((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
892
+    if ((($this->Mailer == 'sendmail') || ($this->Mailer == 'mail')) && (count($this->bcc) > 0)) {
894 893
       $result .= $this->AddrAppend('Bcc', $this->bcc);
895 894
     }
896 895
 
897
-    if(count($this->ReplyTo) > 0) {
896
+    if (count($this->ReplyTo) > 0) {
898 897
       $result .= $this->AddrAppend('Reply-To', $this->ReplyTo);
899 898
     }
900 899
 
901 900
     /* mail() sets the subject itself */
902
-    if($this->Mailer != 'mail') {
901
+    if ($this->Mailer != 'mail') {
903 902
       $result .= $this->HeaderLine('Subject', $this->EncodeHeader($this->SecureHeader($this->Subject)));
904 903
     }
905 904
 
906
-    if($this->MessageID != '') {
907
-      $result .= $this->HeaderLine('Message-ID',$this->MessageID);
905
+    if ($this->MessageID != '') {
906
+      $result .= $this->HeaderLine('Message-ID', $this->MessageID);
908 907
     } else {
909 908
       $result .= sprintf("Message-ID: <%s@%s>%s", $uniq_id, $this->ServerHostname(), $this->LE);
910 909
     }
911 910
     $result .= $this->HeaderLine('X-Priority', $this->Priority);
912
-    $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version ' . $this->Version . ']');
911
+    $result .= $this->HeaderLine('X-Mailer', 'PHPMailer (phpmailer.sourceforge.net) [version '.$this->Version.']');
913 912
 
914
-    if($this->ConfirmReadingTo != '') {
915
-      $result .= $this->HeaderLine('Disposition-Notification-To', '<' . trim($this->ConfirmReadingTo) . '>');
913
+    if ($this->ConfirmReadingTo != '') {
914
+      $result .= $this->HeaderLine('Disposition-Notification-To', '<'.trim($this->ConfirmReadingTo).'>');
916 915
     }
917 916
 
918 917
     // Add custom headers
919
-    for($index = 0; $index < count($this->CustomHeader); $index++) {
918
+    for ($index = 0; $index < count($this->CustomHeader); $index++) {
920 919
       $result .= $this->HeaderLine(trim($this->CustomHeader[$index][0]), $this->EncodeHeader(trim($this->CustomHeader[$index][1])));
921 920
     }
922 921
     if (!$this->sign_key_file) {
@@ -934,7 +933,7 @@  discard block
 block discarded – undo
934 933
    */
935 934
   function GetMailMIME() {
936 935
     $result = '';
937
-    switch($this->message_type) {
936
+    switch ($this->message_type) {
938 937
       case 'plain':
939 938
         $result .= $this->HeaderLine('Content-Transfer-Encoding', $this->Encoding);
940 939
         $result .= sprintf("Content-Type: %s; charset=\"%s\"", $this->ContentType, $this->CharSet);
@@ -942,20 +941,20 @@  discard block
 block discarded – undo
942 941
       case 'attachments':
943 942
         /* fall through */
944 943
       case 'alt_attachments':
945
-        if($this->InlineImageExists()){
944
+        if ($this->InlineImageExists()) {
946 945
           $result .= sprintf("Content-Type: %s;%s\ttype=\"text/html\";%s\tboundary=\"%s\"%s", 'multipart/related', $this->LE, $this->LE, $this->boundary[1], $this->LE);
947 946
         } else {
948 947
           $result .= $this->HeaderLine('Content-Type', 'multipart/mixed;');
949
-          $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
948
+          $result .= $this->TextLine("\tboundary=\"".$this->boundary[1].'"');
950 949
         }
951 950
         break;
952 951
       case 'alt':
953 952
         $result .= $this->HeaderLine('Content-Type', 'multipart/alternative;');
954
-        $result .= $this->TextLine("\tboundary=\"" . $this->boundary[1] . '"');
953
+        $result .= $this->TextLine("\tboundary=\"".$this->boundary[1].'"');
955 954
         break;
956 955
     }
957 956
 
958
-    if($this->Mailer != 'mail') {
957
+    if ($this->Mailer != 'mail') {
959 958
       $result .= $this->LE.$this->LE;
960 959
     }
961 960
 
@@ -975,7 +974,7 @@  discard block
 block discarded – undo
975 974
 
976 975
     $this->SetWordWrap();
977 976
 
978
-    switch($this->message_type) {
977
+    switch ($this->message_type) {
979 978
       case 'alt':
980 979
         $result .= $this->GetBoundary($this->boundary[1], '', 'text/plain', '');
981 980
         $result .= $this->EncodeString($this->AltBody, $this->Encoding);
@@ -996,11 +995,11 @@  discard block
 block discarded – undo
996 995
         break;
997 996
       case 'alt_attachments':
998 997
         $result .= sprintf("--%s%s", $this->boundary[1], $this->LE);
999
-        $result .= sprintf("Content-Type: %s;%s" . "\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
1000
-        $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '') . $this->LE; // Create text body
998
+        $result .= sprintf("Content-Type: %s;%s"."\tboundary=\"%s\"%s", 'multipart/alternative', $this->LE, $this->boundary[2], $this->LE.$this->LE);
999
+        $result .= $this->GetBoundary($this->boundary[2], '', 'text/plain', '').$this->LE; // Create text body
1001 1000
         $result .= $this->EncodeString($this->AltBody, $this->Encoding);
1002 1001
         $result .= $this->LE.$this->LE;
1003
-        $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '') . $this->LE; // Create the HTML body
1002
+        $result .= $this->GetBoundary($this->boundary[2], '', 'text/html', '').$this->LE; // Create the HTML body
1004 1003
         $result .= $this->EncodeString($this->Body, $this->Encoding);
1005 1004
         $result .= $this->LE.$this->LE;
1006 1005
         $result .= $this->EndBoundary($this->boundary[2]);
@@ -1008,7 +1007,7 @@  discard block
 block discarded – undo
1008 1007
         break;
1009 1008
     }
1010 1009
 
1011
-    if($this->IsError()) {
1010
+    if ($this->IsError()) {
1012 1011
       $result = '';
1013 1012
     } else if ($this->sign_key_file) {
1014 1013
       $file = tempnam("", "mail");
@@ -1021,8 +1020,8 @@  discard block
 block discarded – undo
1021 1020
         $fp = fopen($signed, "r");
1022 1021
         $result = fread($fp, filesize($this->sign_key_file));
1023 1022
         $result = '';
1024
-        while(!feof($fp)){
1025
-          $result = $result . fread($fp, 1024);
1023
+        while (!feof($fp)) {
1024
+          $result = $result.fread($fp, 1024);
1026 1025
         }
1027 1026
         fclose($fp);
1028 1027
       } else {
@@ -1043,16 +1042,16 @@  discard block
 block discarded – undo
1043 1042
    */
1044 1043
   function GetBoundary($boundary, $charSet, $contentType, $encoding) {
1045 1044
     $result = '';
1046
-    if($charSet == '') {
1045
+    if ($charSet == '') {
1047 1046
       $charSet = $this->CharSet;
1048 1047
     }
1049
-    if($contentType == '') {
1048
+    if ($contentType == '') {
1050 1049
       $contentType = $this->ContentType;
1051 1050
     }
1052
-    if($encoding == '') {
1051
+    if ($encoding == '') {
1053 1052
       $encoding = $this->Encoding;
1054 1053
     }
1055
-    $result .= $this->TextLine('--' . $boundary);
1054
+    $result .= $this->TextLine('--'.$boundary);
1056 1055
     $result .= sprintf("Content-Type: %s; charset = \"%s\"", $contentType, $charSet);
1057 1056
     $result .= $this->LE;
1058 1057
     $result .= $this->HeaderLine('Content-Transfer-Encoding', $encoding);
@@ -1066,7 +1065,7 @@  discard block
 block discarded – undo
1066 1065
    * @access private
1067 1066
    */
1068 1067
   function EndBoundary($boundary) {
1069
-    return $this->LE . '--' . $boundary . '--' . $this->LE;
1068
+    return $this->LE.'--'.$boundary.'--'.$this->LE;
1070 1069
   }
1071 1070
 
1072 1071
   /**
@@ -1075,16 +1074,16 @@  discard block
 block discarded – undo
1075 1074
    * @return void
1076 1075
    */
1077 1076
   function SetMessageType() {
1078
-    if(count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
1077
+    if (count($this->attachment) < 1 && strlen($this->AltBody) < 1) {
1079 1078
       $this->message_type = 'plain';
1080 1079
     } else {
1081
-      if(count($this->attachment) > 0) {
1080
+      if (count($this->attachment) > 0) {
1082 1081
         $this->message_type = 'attachments';
1083 1082
       }
1084
-      if(strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
1083
+      if (strlen($this->AltBody) > 0 && count($this->attachment) < 1) {
1085 1084
         $this->message_type = 'alt';
1086 1085
       }
1087
-      if(strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
1086
+      if (strlen($this->AltBody) > 0 && count($this->attachment) > 0) {
1088 1087
         $this->message_type = 'alt_attachments';
1089 1088
       }
1090 1089
     }
@@ -1095,7 +1094,7 @@  discard block
 block discarded – undo
1095 1094
    * @return string
1096 1095
    */
1097 1096
   function HeaderLine($name, $value) {
1098
-    return $name . ': ' . $value . $this->LE;
1097
+    return $name.': '.$value.$this->LE;
1099 1098
   }
1100 1099
 
1101 1100
   /**
@@ -1104,7 +1103,7 @@  discard block
 block discarded – undo
1104 1103
    * @return string
1105 1104
    */
1106 1105
   function TextLine($value) {
1107
-    return $value . $this->LE;
1106
+    return $value.$this->LE;
1108 1107
   }
1109 1108
 
1110 1109
   /////////////////////////////////////////////////
@@ -1122,13 +1121,13 @@  discard block
 block discarded – undo
1122 1121
    * @return bool
1123 1122
    */
1124 1123
   function AddAttachment($path, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1125
-    if(!@is_file($path)) {
1126
-      $this->SetError($this->Lang('file_access') . $path);
1124
+    if (!@is_file($path)) {
1125
+      $this->SetError($this->Lang('file_access').$path);
1127 1126
       return false;
1128 1127
     }
1129 1128
 
1130 1129
     $filename = basename($path);
1131
-    if($name == '') {
1130
+    if ($name == '') {
1132 1131
       $name = $filename;
1133 1132
     }
1134 1133
 
@@ -1156,7 +1155,7 @@  discard block
 block discarded – undo
1156 1155
     $mime = array();
1157 1156
 
1158 1157
     /* Add all attachments */
1159
-    for($i = 0; $i < count($this->attachment); $i++) {
1158
+    for ($i = 0; $i < count($this->attachment); $i++) {
1160 1159
       /* Check for string attachment */
1161 1160
       $bString = $this->attachment[$i][5];
1162 1161
       if ($bString) {
@@ -1176,22 +1175,22 @@  discard block
 block discarded – undo
1176 1175
       $mime[] = sprintf("Content-Type: %s; name=\"%s\"%s", $type, $this->EncodeHeader($this->SecureHeader($name)), $this->LE);
1177 1176
       $mime[] = sprintf("Content-Transfer-Encoding: %s%s", $encoding, $this->LE);
1178 1177
 
1179
-      if($disposition == 'inline') {
1178
+      if ($disposition == 'inline') {
1180 1179
         $mime[] = sprintf("Content-ID: <%s>%s", $cid, $this->LE);
1181 1180
       }
1182 1181
 
1183 1182
       $mime[] = sprintf("Content-Disposition: %s; filename=\"%s\"%s", $disposition, $this->EncodeHeader($this->SecureHeader($name)), $this->LE.$this->LE);
1184 1183
 
1185 1184
       /* Encode as string attachment */
1186
-      if($bString) {
1185
+      if ($bString) {
1187 1186
         $mime[] = $this->EncodeString($string, $encoding);
1188
-        if($this->IsError()) {
1187
+        if ($this->IsError()) {
1189 1188
           return '';
1190 1189
         }
1191 1190
         $mime[] = $this->LE.$this->LE;
1192 1191
       } else {
1193 1192
         $mime[] = $this->EncodeFile($path, $encoding);
1194
-        if($this->IsError()) {
1193
+        if ($this->IsError()) {
1195 1194
           return '';
1196 1195
         }
1197 1196
         $mime[] = $this->LE.$this->LE;
@@ -1209,9 +1208,9 @@  discard block
 block discarded – undo
1209 1208
    * @access private
1210 1209
    * @return string
1211 1210
    */
1212
-  function EncodeFile ($path, $encoding = 'base64') {
1213
-    if(!@$fd = fopen($path, 'rb')) {
1214
-      $this->SetError($this->Lang('file_open') . $path);
1211
+  function EncodeFile($path, $encoding = 'base64') {
1212
+    if (!@$fd = fopen($path, 'rb')) {
1213
+      $this->SetError($this->Lang('file_open').$path);
1215 1214
       return '';
1216 1215
     }
1217 1216
     $magic_quotes = get_magic_quotes_runtime();
@@ -1230,9 +1229,9 @@  discard block
 block discarded – undo
1230 1229
    * @access private
1231 1230
    * @return string
1232 1231
    */
1233
-  function EncodeString ($str, $encoding = 'base64') {
1232
+  function EncodeString($str, $encoding = 'base64') {
1234 1233
     $encoded = '';
1235
-    switch(strtolower($encoding)) {
1234
+    switch (strtolower($encoding)) {
1236 1235
       case 'base64':
1237 1236
         /* chunk_split is found in PHP >= 3.0.6 */
1238 1237
         $encoded = chunk_split(base64_encode($str), 76, $this->LE);
@@ -1250,7 +1249,7 @@  discard block
 block discarded – undo
1250 1249
         $encoded = $this->EncodeQP($str);
1251 1250
         break;
1252 1251
       default:
1253
-        $this->SetError($this->Lang('encoding') . $encoding);
1252
+        $this->SetError($this->Lang('encoding').$encoding);
1254 1253
         break;
1255 1254
     }
1256 1255
     return $encoded;
@@ -1261,7 +1260,7 @@  discard block
 block discarded – undo
1261 1260
    * @access private
1262 1261
    * @return string
1263 1262
    */
1264
-  function EncodeHeader ($str, $position = 'text') {
1263
+  function EncodeHeader($str, $position = 'text') {
1265 1264
     $x = 0;
1266 1265
 
1267 1266
     switch (strtolower($position)) {
@@ -1292,7 +1291,7 @@  discard block
 block discarded – undo
1292 1291
 
1293 1292
     $maxlen = 75 - 7 - strlen($this->CharSet);
1294 1293
     /* Try to select the encoding which should produce the shortest output */
1295
-    if (strlen($str)/3 < $x) {
1294
+    if (strlen($str) / 3 < $x) {
1296 1295
       $encoding = 'B';
1297 1296
       if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
1298 1297
      // Use a custom function which correctly encodes and wraps long
@@ -1362,7 +1361,7 @@  discard block
 block discarded – undo
1362 1361
       }
1363 1362
       while (strlen($chunk) > $length);
1364 1363
 
1365
-      $encoded .= $chunk . $this->LE;
1364
+      $encoded .= $chunk.$this->LE;
1366 1365
     }
1367 1366
 
1368 1367
     // Chomp the last linefeed
@@ -1375,37 +1374,37 @@  discard block
 block discarded – undo
1375 1374
    * @access private
1376 1375
    * @return string
1377 1376
    */
1378
-  function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
1379
-    $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
1377
+  function EncodeQP($input = '', $line_max = 76, $space_conv = false) {
1378
+    $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
1380 1379
     $lines = preg_split('/(?:\r\n|\r|\n)/', $input);
1381 1380
     $eol = "\r\n";
1382 1381
     $escape = '=';
1383 1382
     $output = '';
1384
-    while( list(, $line) = each($lines) ) {
1383
+    while (list(, $line) = each($lines)) {
1385 1384
       $linlen = strlen($line);
1386 1385
       $newline = '';
1387
-      for($i = 0; $i < $linlen; $i++) {
1388
-        $c = substr( $line, $i, 1 );
1389
-        $dec = ord( $c );
1390
-        if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
1386
+      for ($i = 0; $i < $linlen; $i++) {
1387
+        $c = substr($line, $i, 1);
1388
+        $dec = ord($c);
1389
+        if (($i == 0) && ($dec == 46)) { // convert first point in the line into =2E
1391 1390
           $c = '=2E';
1392 1391
         }
1393
-        if ( $dec == 32 ) {
1394
-          if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
1392
+        if ($dec == 32) {
1393
+          if ($i == ($linlen - 1)) { // convert space at eol only
1395 1394
             $c = '=20';
1396
-          } else if ( $space_conv ) {
1395
+          } else if ($space_conv) {
1397 1396
             $c = '=20';
1398 1397
           }
1399
-        } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
1400
-          $h2 = floor($dec/16);
1401
-          $h1 = floor($dec%16);
1398
+        } elseif (($dec == 61) || ($dec < 32) || ($dec > 126)) { // always encode "\t", which is *not* required
1399
+          $h2 = floor($dec / 16);
1400
+          $h1 = floor($dec % 16);
1402 1401
           $c = $escape.$hex[$h2].$hex[$h1];
1403 1402
         }
1404
-        if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
1403
+        if ((strlen($newline) + strlen($c)) >= $line_max) { // CRLF is not counted
1405 1404
           $output .= $newline.$escape.$eol; //  soft line break; " =\r\n" is okay
1406 1405
           $newline = '';
1407 1406
           // check if newline first character will be point or not
1408
-          if ( $dec == 46 ) {
1407
+          if ($dec == 46) {
1409 1408
             $c = '=2E';
1410 1409
           }
1411 1410
         }
@@ -1421,7 +1420,7 @@  discard block
 block discarded – undo
1421 1420
    * @access private
1422 1421
    * @return string
1423 1422
    */
1424
-  function EncodeQ ($str, $position = 'text') {
1423
+  function EncodeQ($str, $position = 'text') {
1425 1424
     /* There should not be any EOL in the string */
1426 1425
     $encoded = preg_replace("[\r\n]", '', $str);
1427 1426
 
@@ -1483,13 +1482,13 @@  discard block
 block discarded – undo
1483 1482
    */
1484 1483
   function AddEmbeddedImage($path, $cid, $name = '', $encoding = 'base64', $type = 'application/octet-stream') {
1485 1484
 
1486
-    if(!@is_file($path)) {
1487
-      $this->SetError($this->Lang('file_access') . $path);
1485
+    if (!@is_file($path)) {
1486
+      $this->SetError($this->Lang('file_access').$path);
1488 1487
       return false;
1489 1488
     }
1490 1489
 
1491 1490
     $filename = basename($path);
1492
-    if($name == '') {
1491
+    if ($name == '') {
1493 1492
       $name = $filename;
1494 1493
     }
1495 1494
 
@@ -1514,8 +1513,8 @@  discard block
 block discarded – undo
1514 1513
    */
1515 1514
   function InlineImageExists() {
1516 1515
     $result = false;
1517
-    for($i = 0; $i < count($this->attachment); $i++) {
1518
-      if($this->attachment[$i][6] == 'inline') {
1516
+    for ($i = 0; $i < count($this->attachment); $i++) {
1517
+      if ($this->attachment[$i][6] == 'inline') {
1519 1518
         $result = true;
1520 1519
         break;
1521 1520
       }
@@ -1612,7 +1611,7 @@  discard block
 block discarded – undo
1612 1611
     $tz = date('Z');
1613 1612
     $tzs = ($tz < 0) ? '-' : '+';
1614 1613
     $tz = abs($tz);
1615
-    $tz = (int)($tz/3600)*100 + ($tz%3600)/60;
1614
+    $tz = (int) ($tz / 3600) * 100 + ($tz % 3600) / 60;
1616 1615
     $result = sprintf("%s %s%04d", date('D, j M Y H:i:s'), $tzs, $tz);
1617 1616
 
1618 1617
     return $result;
@@ -1629,14 +1628,14 @@  discard block
 block discarded – undo
1629 1628
     global $HTTP_SERVER_VARS;
1630 1629
     global $HTTP_ENV_VARS;
1631 1630
 
1632
-    if(!isset($_SERVER)) {
1631
+    if (!isset($_SERVER)) {
1633 1632
       $_SERVER = $HTTP_SERVER_VARS;
1634
-      if(!isset($_SERVER['REMOTE_ADDR'])) {
1633
+      if (!isset($_SERVER['REMOTE_ADDR'])) {
1635 1634
         $_SERVER = $HTTP_ENV_VARS; // must be Apache
1636 1635
       }
1637 1636
     }
1638 1637
 
1639
-    if(isset($_SERVER[$varName])) {
1638
+    if (isset($_SERVER[$varName])) {
1640 1639
       return $_SERVER[$varName];
1641 1640
     } else {
1642 1641
       return '';
@@ -1666,14 +1665,14 @@  discard block
 block discarded – undo
1666 1665
    * @return string
1667 1666
    */
1668 1667
   function Lang($key) {
1669
-    if(count($this->language) < 1) {
1668
+    if (count($this->language) < 1) {
1670 1669
       $this->SetLanguage('en'); // set the default language
1671 1670
     }
1672 1671
 
1673
-    if(isset($this->language[$key])) {
1672
+    if (isset($this->language[$key])) {
1674 1673
       return $this->language[$key];
1675 1674
     } else {
1676
-      return 'Language string failed to load: ' . $key;
1675
+      return 'Language string failed to load: '.$key;
1677 1676
     }
1678 1677
   }
1679 1678
 
@@ -1710,22 +1709,22 @@  discard block
 block discarded – undo
1710 1709
    * @access public
1711 1710
    * @return $message
1712 1711
    */
1713
-  function MsgHTML($message,$basedir='') {
1712
+  function MsgHTML($message, $basedir = '') {
1714 1713
     preg_match_all("/(src|background)=\"(.*)\"/Ui", $message, $images);
1715
-    if(isset($images[2])) {
1716
-      foreach($images[2] as $i => $url) {
1714
+    if (isset($images[2])) {
1715
+      foreach ($images[2] as $i => $url) {
1717 1716
         // do not change urls for absolute images (thanks to corvuscorax)
1718
-        if (!preg_match('/^[A-z][A-z]*:\/\//',$url)) {
1717
+        if (!preg_match('/^[A-z][A-z]*:\/\//', $url)) {
1719 1718
           $filename = basename($url);
1720 1719
           $directory = dirname($url);
1721
-          ($directory == '.')?$directory='':'';
1722
-          $cid = 'cid:' . md5($filename);
1720
+          ($directory == '.') ? $directory = '' : '';
1721
+          $cid = 'cid:'.md5($filename);
1723 1722
           $fileParts = split("\.", $filename);
1724 1723
           $ext = $fileParts[1];
1725 1724
           $mimeType = $this->_mime_types($ext);
1726
-          if ( strlen($basedir) > 1 && substr($basedir,-1) != '/') { $basedir .= '/'; }
1727
-          if ( strlen($directory) > 1 && substr($directory,-1) != '/') { $directory .= '/'; }
1728
-          if ( $this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64',$mimeType) ) {
1725
+          if (strlen($basedir) > 1 && substr($basedir, -1) != '/') { $basedir .= '/'; }
1726
+          if (strlen($directory) > 1 && substr($directory, -1) != '/') { $directory .= '/'; }
1727
+          if ($this->AddEmbeddedImage($basedir.$directory.$filename, md5($filename), $filename, 'base64', $mimeType)) {
1729 1728
             $message = preg_replace("/".$images[1][$i]."=\"".preg_quote($url, '/')."\"/Ui", $images[1][$i]."=\"".$cid."\"", $message);
1730 1729
           }
1731 1730
         }
@@ -1733,12 +1732,12 @@  discard block
 block discarded – undo
1733 1732
     }
1734 1733
     $this->IsHTML(true);
1735 1734
     $this->Body = $message;
1736
-    $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$message)));
1737
-    if ( !empty($textMsg) && empty($this->AltBody) ) {
1735
+    $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s', '', $message)));
1736
+    if (!empty($textMsg) && empty($this->AltBody)) {
1738 1737
       $this->AltBody = html_entity_decode($textMsg);
1739 1738
     }
1740
-    if ( empty($this->AltBody) ) {
1741
-      $this->AltBody = 'To view this email message, open the email in with HTML compatibility!' . "\n\n";
1739
+    if (empty($this->AltBody)) {
1740
+      $this->AltBody = 'To view this email message, open the email in with HTML compatibility!'."\n\n";
1742 1741
     }
1743 1742
   }
1744 1743
 
@@ -1836,7 +1835,7 @@  discard block
 block discarded – undo
1836 1835
       'xsl'   =>  'text/xml',
1837 1836
       'zip'   =>  'application/zip'
1838 1837
     );
1839
-    return ( ! isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
1838
+    return (!isset($mimes[strtolower($ext)])) ? 'application/octet-stream' : $mimes[strtolower($ext)];
1840 1839
   }
1841 1840
 
1842 1841
   /**
@@ -1850,11 +1849,11 @@  discard block
 block discarded – undo
1850 1849
    * @param mixed $value Parameter Value
1851 1850
    * NOTE: will not work with arrays, there are no arrays to set/reset
1852 1851
    */
1853
-  function set ( $name, $value = '' ) {
1854
-    if ( isset($this->$name) ) {
1852
+  function set($name, $value = '') {
1853
+    if (isset($this->$name)) {
1855 1854
       $this->$name = $value;
1856 1855
     } else {
1857
-      $this->SetError('Cannot set or reset variable ' . $name);
1856
+      $this->SetError('Cannot set or reset variable '.$name);
1858 1857
       return false;
1859 1858
     }
1860 1859
   }
Please login to merge, or discard this patch.