web/wp-includes/SimplePie/HTTP/Parser.php
author Anthony Ly <anthonyly.com@gmail.com>
Wed, 19 Dec 2012 17:46:52 -0800
changeset 204 09a1c134465b
permissions -rw-r--r--
man wordpress + plugins order post + slideshow
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
204
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     1
<?php
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     2
/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     3
 * SimplePie
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     4
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     5
 * A PHP-Based RSS and Atom Feed Framework.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     6
 * Takes the hard work out of managing a complete RSS/Atom solution.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     7
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     8
 * Copyright (c) 2004-2012, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
     9
 * All rights reserved.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    10
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    11
 * Redistribution and use in source and binary forms, with or without modification, are
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    12
 * permitted provided that the following conditions are met:
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    13
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    14
 * 	* Redistributions of source code must retain the above copyright notice, this list of
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    15
 * 	  conditions and the following disclaimer.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    16
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    17
 * 	* Redistributions in binary form must reproduce the above copyright notice, this list
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    18
 * 	  of conditions and the following disclaimer in the documentation and/or other materials
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    19
 * 	  provided with the distribution.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    20
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    21
 * 	* Neither the name of the SimplePie Team nor the names of its contributors may be used
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    22
 * 	  to endorse or promote products derived from this software without specific prior
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    23
 * 	  written permission.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    24
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    25
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    26
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    27
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    28
 * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    29
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    30
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    31
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    32
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    33
 * POSSIBILITY OF SUCH DAMAGE.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    34
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    35
 * @package SimplePie
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    36
 * @version 1.3.1
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    37
 * @copyright 2004-2012 Ryan Parman, Geoffrey Sneddon, Ryan McCue
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    38
 * @author Ryan Parman
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    39
 * @author Geoffrey Sneddon
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    40
 * @author Ryan McCue
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    41
 * @link http://simplepie.org/ SimplePie
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    42
 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    43
 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    44
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    45
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    46
/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    47
 * HTTP Response Parser
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    48
 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    49
 * @package SimplePie
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    50
 * @subpackage HTTP
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    51
 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    52
class SimplePie_HTTP_Parser
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    53
{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    54
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    55
	 * HTTP Version
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    56
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    57
	 * @var float
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    58
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    59
	public $http_version = 0.0;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    60
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    61
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    62
	 * Status code
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    63
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    64
	 * @var int
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    65
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    66
	public $status_code = 0;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    67
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    68
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    69
	 * Reason phrase
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    70
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    71
	 * @var string
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    72
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    73
	public $reason = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    74
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    75
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    76
	 * Key/value pairs of the headers
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    77
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    78
	 * @var array
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    79
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    80
	public $headers = array();
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    81
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    82
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    83
	 * Body of the response
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    84
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    85
	 * @var string
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    86
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    87
	public $body = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    88
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    89
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    90
	 * Current state of the state machine
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    91
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    92
	 * @var string
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    93
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    94
	protected $state = 'http_version';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    95
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    96
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    97
	 * Input data
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    98
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
    99
	 * @var string
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   100
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   101
	protected $data = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   102
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   103
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   104
	 * Input data length (to avoid calling strlen() everytime this is needed)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   105
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   106
	 * @var int
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   107
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   108
	protected $data_length = 0;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   109
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   110
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   111
	 * Current position of the pointer
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   112
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   113
	 * @var int
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   114
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   115
	protected $position = 0;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   116
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   117
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   118
	 * Name of the hedaer currently being parsed
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   119
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   120
	 * @var string
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   121
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   122
	protected $name = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   123
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   124
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   125
	 * Value of the hedaer currently being parsed
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   126
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   127
	 * @var string
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   128
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   129
	protected $value = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   130
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   131
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   132
	 * Create an instance of the class with the input data
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   133
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   134
	 * @param string $data Input data
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   135
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   136
	public function __construct($data)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   137
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   138
		$this->data = $data;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   139
		$this->data_length = strlen($this->data);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   140
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   141
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   142
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   143
	 * Parse the input data
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   144
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   145
	 * @return bool true on success, false on failure
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   146
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   147
	public function parse()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   148
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   149
		while ($this->state && $this->state !== 'emit' && $this->has_data())
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   150
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   151
			$state = $this->state;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   152
			$this->$state();
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   153
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   154
		$this->data = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   155
		if ($this->state === 'emit' || $this->state === 'body')
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   156
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   157
			return true;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   158
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   159
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   160
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   161
			$this->http_version = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   162
			$this->status_code = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   163
			$this->reason = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   164
			$this->headers = array();
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   165
			$this->body = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   166
			return false;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   167
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   168
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   169
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   170
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   171
	 * Check whether there is data beyond the pointer
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   172
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   173
	 * @return bool true if there is further data, false if not
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   174
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   175
	protected function has_data()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   176
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   177
		return (bool) ($this->position < $this->data_length);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   178
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   179
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   180
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   181
	 * See if the next character is LWS
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   182
	 *
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   183
	 * @return bool true if the next character is LWS, false if not
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   184
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   185
	protected function is_linear_whitespace()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   186
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   187
		return (bool) ($this->data[$this->position] === "\x09"
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   188
			|| $this->data[$this->position] === "\x20"
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   189
			|| ($this->data[$this->position] === "\x0A"
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   190
				&& isset($this->data[$this->position + 1])
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   191
				&& ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20")));
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   192
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   193
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   194
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   195
	 * Parse the HTTP version
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   196
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   197
	protected function http_version()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   198
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   199
		if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/')
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   200
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   201
			$len = strspn($this->data, '0123456789.', 5);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   202
			$this->http_version = substr($this->data, 5, $len);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   203
			$this->position += 5 + $len;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   204
			if (substr_count($this->http_version, '.') <= 1)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   205
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   206
				$this->http_version = (float) $this->http_version;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   207
				$this->position += strspn($this->data, "\x09\x20", $this->position);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   208
				$this->state = 'status';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   209
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   210
			else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   211
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   212
				$this->state = false;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   213
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   214
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   215
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   216
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   217
			$this->state = false;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   218
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   219
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   220
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   221
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   222
	 * Parse the status code
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   223
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   224
	protected function status()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   225
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   226
		if ($len = strspn($this->data, '0123456789', $this->position))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   227
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   228
			$this->status_code = (int) substr($this->data, $this->position, $len);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   229
			$this->position += $len;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   230
			$this->state = 'reason';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   231
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   232
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   233
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   234
			$this->state = false;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   235
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   236
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   237
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   238
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   239
	 * Parse the reason phrase
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   240
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   241
	protected function reason()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   242
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   243
		$len = strcspn($this->data, "\x0A", $this->position);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   244
		$this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20");
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   245
		$this->position += $len + 1;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   246
		$this->state = 'new_line';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   247
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   248
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   249
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   250
	 * Deal with a new line, shifting data around as needed
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   251
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   252
	protected function new_line()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   253
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   254
		$this->value = trim($this->value, "\x0D\x20");
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   255
		if ($this->name !== '' && $this->value !== '')
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   256
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   257
			$this->name = strtolower($this->name);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   258
			// We should only use the last Content-Type header. c.f. issue #1
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   259
			if (isset($this->headers[$this->name]) && $this->name !== 'content-type')
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   260
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   261
				$this->headers[$this->name] .= ', ' . $this->value;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   262
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   263
			else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   264
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   265
				$this->headers[$this->name] = $this->value;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   266
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   267
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   268
		$this->name = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   269
		$this->value = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   270
		if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A")
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   271
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   272
			$this->position += 2;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   273
			$this->state = 'body';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   274
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   275
		elseif ($this->data[$this->position] === "\x0A")
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   276
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   277
			$this->position++;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   278
			$this->state = 'body';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   279
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   280
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   281
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   282
			$this->state = 'name';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   283
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   284
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   285
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   286
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   287
	 * Parse a header name
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   288
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   289
	protected function name()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   290
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   291
		$len = strcspn($this->data, "\x0A:", $this->position);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   292
		if (isset($this->data[$this->position + $len]))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   293
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   294
			if ($this->data[$this->position + $len] === "\x0A")
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   295
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   296
				$this->position += $len;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   297
				$this->state = 'new_line';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   298
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   299
			else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   300
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   301
				$this->name = substr($this->data, $this->position, $len);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   302
				$this->position += $len + 1;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   303
				$this->state = 'value';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   304
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   305
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   306
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   307
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   308
			$this->state = false;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   309
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   310
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   311
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   312
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   313
	 * Parse LWS, replacing consecutive LWS characters with a single space
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   314
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   315
	protected function linear_whitespace()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   316
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   317
		do
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   318
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   319
			if (substr($this->data, $this->position, 2) === "\x0D\x0A")
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   320
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   321
				$this->position += 2;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   322
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   323
			elseif ($this->data[$this->position] === "\x0A")
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   324
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   325
				$this->position++;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   326
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   327
			$this->position += strspn($this->data, "\x09\x20", $this->position);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   328
		} while ($this->has_data() && $this->is_linear_whitespace());
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   329
		$this->value .= "\x20";
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   330
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   331
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   332
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   333
	 * See what state to move to while within non-quoted header values
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   334
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   335
	protected function value()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   336
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   337
		if ($this->is_linear_whitespace())
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   338
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   339
			$this->linear_whitespace();
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   340
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   341
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   342
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   343
			switch ($this->data[$this->position])
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   344
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   345
				case '"':
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   346
					// Workaround for ETags: we have to include the quotes as
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   347
					// part of the tag.
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   348
					if (strtolower($this->name) === 'etag')
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   349
					{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   350
						$this->value .= '"';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   351
						$this->position++;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   352
						$this->state = 'value_char';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   353
						break;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   354
					}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   355
					$this->position++;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   356
					$this->state = 'quote';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   357
					break;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   358
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   359
				case "\x0A":
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   360
					$this->position++;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   361
					$this->state = 'new_line';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   362
					break;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   363
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   364
				default:
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   365
					$this->state = 'value_char';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   366
					break;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   367
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   368
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   369
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   370
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   371
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   372
	 * Parse a header value while outside quotes
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   373
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   374
	protected function value_char()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   375
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   376
		$len = strcspn($this->data, "\x09\x20\x0A\"", $this->position);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   377
		$this->value .= substr($this->data, $this->position, $len);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   378
		$this->position += $len;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   379
		$this->state = 'value';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   380
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   381
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   382
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   383
	 * See what state to move to while within quoted header values
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   384
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   385
	protected function quote()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   386
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   387
		if ($this->is_linear_whitespace())
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   388
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   389
			$this->linear_whitespace();
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   390
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   391
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   392
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   393
			switch ($this->data[$this->position])
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   394
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   395
				case '"':
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   396
					$this->position++;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   397
					$this->state = 'value';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   398
					break;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   399
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   400
				case "\x0A":
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   401
					$this->position++;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   402
					$this->state = 'new_line';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   403
					break;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   404
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   405
				case '\\':
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   406
					$this->position++;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   407
					$this->state = 'quote_escaped';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   408
					break;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   409
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   410
				default:
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   411
					$this->state = 'quote_char';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   412
					break;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   413
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   414
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   415
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   416
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   417
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   418
	 * Parse a header value while within quotes
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   419
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   420
	protected function quote_char()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   421
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   422
		$len = strcspn($this->data, "\x09\x20\x0A\"\\", $this->position);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   423
		$this->value .= substr($this->data, $this->position, $len);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   424
		$this->position += $len;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   425
		$this->state = 'value';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   426
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   427
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   428
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   429
	 * Parse an escaped character within quotes
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   430
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   431
	protected function quote_escaped()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   432
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   433
		$this->value .= $this->data[$this->position];
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   434
		$this->position++;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   435
		$this->state = 'quote';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   436
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   437
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   438
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   439
	 * Parse the body
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   440
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   441
	protected function body()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   442
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   443
		$this->body = substr($this->data, $this->position);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   444
		if (!empty($this->headers['transfer-encoding']))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   445
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   446
			unset($this->headers['transfer-encoding']);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   447
			$this->state = 'chunked';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   448
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   449
		else
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   450
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   451
			$this->state = 'emit';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   452
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   453
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   454
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   455
	/**
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   456
	 * Parsed a "Transfer-Encoding: chunked" body
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   457
	 */
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   458
	protected function chunked()
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   459
	{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   460
		if (!preg_match('/^([0-9a-f]+)[^\r\n]*\r\n/i', trim($this->body)))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   461
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   462
			$this->state = 'emit';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   463
			return;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   464
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   465
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   466
		$decoded = '';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   467
		$encoded = $this->body;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   468
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   469
		while (true)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   470
		{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   471
			$is_chunked = (bool) preg_match( '/^([0-9a-f]+)[^\r\n]*\r\n/i', $encoded, $matches );
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   472
			if (!$is_chunked)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   473
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   474
				// Looks like it's not chunked after all
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   475
				$this->state = 'emit';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   476
				return;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   477
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   478
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   479
			$length = hexdec(trim($matches[1]));
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   480
			if ($length === 0)
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   481
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   482
				// Ignore trailer headers
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   483
				$this->state = 'emit';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   484
				$this->body = $decoded;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   485
				return;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   486
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   487
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   488
			$chunk_length = strlen($matches[0]);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   489
			$decoded .= $part = substr($encoded, $chunk_length, $length);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   490
			$encoded = substr($encoded, $chunk_length + $length + 2);
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   491
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   492
			if (trim($encoded) === '0' || empty($encoded))
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   493
			{
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   494
				$this->state = 'emit';
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   495
				$this->body = $decoded;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   496
				return;
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   497
			}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   498
		}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   499
	}
09a1c134465b man wordpress + plugins order post + slideshow
Anthony Ly <anthonyly.com@gmail.com>
parents:
diff changeset
   500
}