Edit File by line
/home/barbar84/public_h.../wp-inclu.../SimplePi.../XML/Declarat...
File: Parser.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* SimplePie
[2] Fix | Delete
*
[3] Fix | Delete
* A PHP-Based RSS and Atom Feed Framework.
[4] Fix | Delete
* Takes the hard work out of managing a complete RSS/Atom solution.
[5] Fix | Delete
*
[6] Fix | Delete
* Copyright (c) 2004-2016, Ryan Parman, Sam Sneddon, Ryan McCue, and contributors
[7] Fix | Delete
* All rights reserved.
[8] Fix | Delete
*
[9] Fix | Delete
* Redistribution and use in source and binary forms, with or without modification, are
[10] Fix | Delete
* permitted provided that the following conditions are met:
[11] Fix | Delete
*
[12] Fix | Delete
* * Redistributions of source code must retain the above copyright notice, this list of
[13] Fix | Delete
* conditions and the following disclaimer.
[14] Fix | Delete
*
[15] Fix | Delete
* * Redistributions in binary form must reproduce the above copyright notice, this list
[16] Fix | Delete
* of conditions and the following disclaimer in the documentation and/or other materials
[17] Fix | Delete
* provided with the distribution.
[18] Fix | Delete
*
[19] Fix | Delete
* * Neither the name of the SimplePie Team nor the names of its contributors may be used
[20] Fix | Delete
* to endorse or promote products derived from this software without specific prior
[21] Fix | Delete
* written permission.
[22] Fix | Delete
*
[23] Fix | Delete
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
[24] Fix | Delete
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
[25] Fix | Delete
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
[26] Fix | Delete
* AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
[27] Fix | Delete
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
[28] Fix | Delete
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
[29] Fix | Delete
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
[30] Fix | Delete
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
[31] Fix | Delete
* POSSIBILITY OF SUCH DAMAGE.
[32] Fix | Delete
*
[33] Fix | Delete
* @package SimplePie
[34] Fix | Delete
* @copyright 2004-2016 Ryan Parman, Sam Sneddon, Ryan McCue
[35] Fix | Delete
* @author Ryan Parman
[36] Fix | Delete
* @author Sam Sneddon
[37] Fix | Delete
* @author Ryan McCue
[38] Fix | Delete
* @link http://simplepie.org/ SimplePie
[39] Fix | Delete
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
[40] Fix | Delete
*/
[41] Fix | Delete
[42] Fix | Delete
[43] Fix | Delete
/**
[44] Fix | Delete
* Parses the XML Declaration
[45] Fix | Delete
*
[46] Fix | Delete
* @package SimplePie
[47] Fix | Delete
* @subpackage Parsing
[48] Fix | Delete
*/
[49] Fix | Delete
class SimplePie_XML_Declaration_Parser
[50] Fix | Delete
{
[51] Fix | Delete
/**
[52] Fix | Delete
* XML Version
[53] Fix | Delete
*
[54] Fix | Delete
* @access public
[55] Fix | Delete
* @var string
[56] Fix | Delete
*/
[57] Fix | Delete
var $version = '1.0';
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Encoding
[61] Fix | Delete
*
[62] Fix | Delete
* @access public
[63] Fix | Delete
* @var string
[64] Fix | Delete
*/
[65] Fix | Delete
var $encoding = 'UTF-8';
[66] Fix | Delete
[67] Fix | Delete
/**
[68] Fix | Delete
* Standalone
[69] Fix | Delete
*
[70] Fix | Delete
* @access public
[71] Fix | Delete
* @var bool
[72] Fix | Delete
*/
[73] Fix | Delete
var $standalone = false;
[74] Fix | Delete
[75] Fix | Delete
/**
[76] Fix | Delete
* Current state of the state machine
[77] Fix | Delete
*
[78] Fix | Delete
* @access private
[79] Fix | Delete
* @var string
[80] Fix | Delete
*/
[81] Fix | Delete
var $state = 'before_version_name';
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Input data
[85] Fix | Delete
*
[86] Fix | Delete
* @access private
[87] Fix | Delete
* @var string
[88] Fix | Delete
*/
[89] Fix | Delete
var $data = '';
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* Input data length (to avoid calling strlen() everytime this is needed)
[93] Fix | Delete
*
[94] Fix | Delete
* @access private
[95] Fix | Delete
* @var int
[96] Fix | Delete
*/
[97] Fix | Delete
var $data_length = 0;
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Current position of the pointer
[101] Fix | Delete
*
[102] Fix | Delete
* @var int
[103] Fix | Delete
* @access private
[104] Fix | Delete
*/
[105] Fix | Delete
var $position = 0;
[106] Fix | Delete
[107] Fix | Delete
/**
[108] Fix | Delete
* Create an instance of the class with the input data
[109] Fix | Delete
*
[110] Fix | Delete
* @access public
[111] Fix | Delete
* @param string $data Input data
[112] Fix | Delete
*/
[113] Fix | Delete
public function __construct($data)
[114] Fix | Delete
{
[115] Fix | Delete
$this->data = $data;
[116] Fix | Delete
$this->data_length = strlen($this->data);
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
/**
[120] Fix | Delete
* Parse the input data
[121] Fix | Delete
*
[122] Fix | Delete
* @access public
[123] Fix | Delete
* @return bool true on success, false on failure
[124] Fix | Delete
*/
[125] Fix | Delete
public function parse()
[126] Fix | Delete
{
[127] Fix | Delete
while ($this->state && $this->state !== 'emit' && $this->has_data())
[128] Fix | Delete
{
[129] Fix | Delete
$state = $this->state;
[130] Fix | Delete
$this->$state();
[131] Fix | Delete
}
[132] Fix | Delete
$this->data = '';
[133] Fix | Delete
if ($this->state === 'emit')
[134] Fix | Delete
{
[135] Fix | Delete
return true;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
$this->version = '';
[139] Fix | Delete
$this->encoding = '';
[140] Fix | Delete
$this->standalone = '';
[141] Fix | Delete
return false;
[142] Fix | Delete
}
[143] Fix | Delete
[144] Fix | Delete
/**
[145] Fix | Delete
* Check whether there is data beyond the pointer
[146] Fix | Delete
*
[147] Fix | Delete
* @access private
[148] Fix | Delete
* @return bool true if there is further data, false if not
[149] Fix | Delete
*/
[150] Fix | Delete
public function has_data()
[151] Fix | Delete
{
[152] Fix | Delete
return (bool) ($this->position < $this->data_length);
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
/**
[156] Fix | Delete
* Advance past any whitespace
[157] Fix | Delete
*
[158] Fix | Delete
* @return int Number of whitespace characters passed
[159] Fix | Delete
*/
[160] Fix | Delete
public function skip_whitespace()
[161] Fix | Delete
{
[162] Fix | Delete
$whitespace = strspn($this->data, "\x09\x0A\x0D\x20", $this->position);
[163] Fix | Delete
$this->position += $whitespace;
[164] Fix | Delete
return $whitespace;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
/**
[168] Fix | Delete
* Read value
[169] Fix | Delete
*/
[170] Fix | Delete
public function get_value()
[171] Fix | Delete
{
[172] Fix | Delete
$quote = substr($this->data, $this->position, 1);
[173] Fix | Delete
if ($quote === '"' || $quote === "'")
[174] Fix | Delete
{
[175] Fix | Delete
$this->position++;
[176] Fix | Delete
$len = strcspn($this->data, $quote, $this->position);
[177] Fix | Delete
if ($this->has_data())
[178] Fix | Delete
{
[179] Fix | Delete
$value = substr($this->data, $this->position, $len);
[180] Fix | Delete
$this->position += $len + 1;
[181] Fix | Delete
return $value;
[182] Fix | Delete
}
[183] Fix | Delete
}
[184] Fix | Delete
return false;
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
public function before_version_name()
[188] Fix | Delete
{
[189] Fix | Delete
if ($this->skip_whitespace())
[190] Fix | Delete
{
[191] Fix | Delete
$this->state = 'version_name';
[192] Fix | Delete
}
[193] Fix | Delete
else
[194] Fix | Delete
{
[195] Fix | Delete
$this->state = false;
[196] Fix | Delete
}
[197] Fix | Delete
}
[198] Fix | Delete
[199] Fix | Delete
public function version_name()
[200] Fix | Delete
{
[201] Fix | Delete
if (substr($this->data, $this->position, 7) === 'version')
[202] Fix | Delete
{
[203] Fix | Delete
$this->position += 7;
[204] Fix | Delete
$this->skip_whitespace();
[205] Fix | Delete
$this->state = 'version_equals';
[206] Fix | Delete
}
[207] Fix | Delete
else
[208] Fix | Delete
{
[209] Fix | Delete
$this->state = false;
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
[213] Fix | Delete
public function version_equals()
[214] Fix | Delete
{
[215] Fix | Delete
if (substr($this->data, $this->position, 1) === '=')
[216] Fix | Delete
{
[217] Fix | Delete
$this->position++;
[218] Fix | Delete
$this->skip_whitespace();
[219] Fix | Delete
$this->state = 'version_value';
[220] Fix | Delete
}
[221] Fix | Delete
else
[222] Fix | Delete
{
[223] Fix | Delete
$this->state = false;
[224] Fix | Delete
}
[225] Fix | Delete
}
[226] Fix | Delete
[227] Fix | Delete
public function version_value()
[228] Fix | Delete
{
[229] Fix | Delete
if ($this->version = $this->get_value())
[230] Fix | Delete
{
[231] Fix | Delete
$this->skip_whitespace();
[232] Fix | Delete
if ($this->has_data())
[233] Fix | Delete
{
[234] Fix | Delete
$this->state = 'encoding_name';
[235] Fix | Delete
}
[236] Fix | Delete
else
[237] Fix | Delete
{
[238] Fix | Delete
$this->state = 'emit';
[239] Fix | Delete
}
[240] Fix | Delete
}
[241] Fix | Delete
else
[242] Fix | Delete
{
[243] Fix | Delete
$this->state = false;
[244] Fix | Delete
}
[245] Fix | Delete
}
[246] Fix | Delete
[247] Fix | Delete
public function encoding_name()
[248] Fix | Delete
{
[249] Fix | Delete
if (substr($this->data, $this->position, 8) === 'encoding')
[250] Fix | Delete
{
[251] Fix | Delete
$this->position += 8;
[252] Fix | Delete
$this->skip_whitespace();
[253] Fix | Delete
$this->state = 'encoding_equals';
[254] Fix | Delete
}
[255] Fix | Delete
else
[256] Fix | Delete
{
[257] Fix | Delete
$this->state = 'standalone_name';
[258] Fix | Delete
}
[259] Fix | Delete
}
[260] Fix | Delete
[261] Fix | Delete
public function encoding_equals()
[262] Fix | Delete
{
[263] Fix | Delete
if (substr($this->data, $this->position, 1) === '=')
[264] Fix | Delete
{
[265] Fix | Delete
$this->position++;
[266] Fix | Delete
$this->skip_whitespace();
[267] Fix | Delete
$this->state = 'encoding_value';
[268] Fix | Delete
}
[269] Fix | Delete
else
[270] Fix | Delete
{
[271] Fix | Delete
$this->state = false;
[272] Fix | Delete
}
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
public function encoding_value()
[276] Fix | Delete
{
[277] Fix | Delete
if ($this->encoding = $this->get_value())
[278] Fix | Delete
{
[279] Fix | Delete
$this->skip_whitespace();
[280] Fix | Delete
if ($this->has_data())
[281] Fix | Delete
{
[282] Fix | Delete
$this->state = 'standalone_name';
[283] Fix | Delete
}
[284] Fix | Delete
else
[285] Fix | Delete
{
[286] Fix | Delete
$this->state = 'emit';
[287] Fix | Delete
}
[288] Fix | Delete
}
[289] Fix | Delete
else
[290] Fix | Delete
{
[291] Fix | Delete
$this->state = false;
[292] Fix | Delete
}
[293] Fix | Delete
}
[294] Fix | Delete
[295] Fix | Delete
public function standalone_name()
[296] Fix | Delete
{
[297] Fix | Delete
if (substr($this->data, $this->position, 10) === 'standalone')
[298] Fix | Delete
{
[299] Fix | Delete
$this->position += 10;
[300] Fix | Delete
$this->skip_whitespace();
[301] Fix | Delete
$this->state = 'standalone_equals';
[302] Fix | Delete
}
[303] Fix | Delete
else
[304] Fix | Delete
{
[305] Fix | Delete
$this->state = false;
[306] Fix | Delete
}
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
public function standalone_equals()
[310] Fix | Delete
{
[311] Fix | Delete
if (substr($this->data, $this->position, 1) === '=')
[312] Fix | Delete
{
[313] Fix | Delete
$this->position++;
[314] Fix | Delete
$this->skip_whitespace();
[315] Fix | Delete
$this->state = 'standalone_value';
[316] Fix | Delete
}
[317] Fix | Delete
else
[318] Fix | Delete
{
[319] Fix | Delete
$this->state = false;
[320] Fix | Delete
}
[321] Fix | Delete
}
[322] Fix | Delete
[323] Fix | Delete
public function standalone_value()
[324] Fix | Delete
{
[325] Fix | Delete
if ($standalone = $this->get_value())
[326] Fix | Delete
{
[327] Fix | Delete
switch ($standalone)
[328] Fix | Delete
{
[329] Fix | Delete
case 'yes':
[330] Fix | Delete
$this->standalone = true;
[331] Fix | Delete
break;
[332] Fix | Delete
[333] Fix | Delete
case 'no':
[334] Fix | Delete
$this->standalone = false;
[335] Fix | Delete
break;
[336] Fix | Delete
[337] Fix | Delete
default:
[338] Fix | Delete
$this->state = false;
[339] Fix | Delete
return;
[340] Fix | Delete
}
[341] Fix | Delete
[342] Fix | Delete
$this->skip_whitespace();
[343] Fix | Delete
if ($this->has_data())
[344] Fix | Delete
{
[345] Fix | Delete
$this->state = false;
[346] Fix | Delete
}
[347] Fix | Delete
else
[348] Fix | Delete
{
[349] Fix | Delete
$this->state = 'emit';
[350] Fix | Delete
}
[351] Fix | Delete
}
[352] Fix | Delete
else
[353] Fix | Delete
{
[354] Fix | Delete
$this->state = false;
[355] Fix | Delete
}
[356] Fix | Delete
}
[357] Fix | Delete
}
[358] Fix | Delete
[359] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function