???????????????
???????????????
Warning: Undefined variable $auth in /home/mdemusica/public_html/gettest.php on line 544
Warning: Trying to access array offset on value of type null in /home/mdemusica/public_html/gettest.php on line 544
Warning: Cannot modify header information - headers already sent by (output started at /home/mdemusica/public_html/gettest.php:1) in /home/mdemusica/public_html/gettest.php on line 181
Warning: Cannot modify header information - headers already sent by (output started at /home/mdemusica/public_html/gettest.php:1) in /home/mdemusica/public_html/gettest.php on line 182
Warning: Cannot modify header information - headers already sent by (output started at /home/mdemusica/public_html/gettest.php:1) in /home/mdemusica/public_html/gettest.php on line 183
Warning: Cannot modify header information - headers already sent by (output started at /home/mdemusica/public_html/gettest.php:1) in /home/mdemusica/public_html/gettest.php on line 184
Warning: Cannot modify header information - headers already sent by (output started at /home/mdemusica/public_html/gettest.php:1) in /home/mdemusica/public_html/gettest.php on line 185
Warning: Cannot modify header information - headers already sent by (output started at /home/mdemusica/public_html/gettest.php:1) in /home/mdemusica/public_html/gettest.php on line 186
autoloader.php 0000644 00000004005 15143517255 0007423 0 ustar 00 path = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'library';
}
/**
* Autoloader
*
* @param string $class The name of the class to attempt to load.
*/
public function autoload($class)
{
// Only load the class if it starts with "SimplePie"
if (strpos($class, 'SimplePie') !== 0)
{
return;
}
$filename = $this->path . DIRECTORY_SEPARATOR . str_replace('_', DIRECTORY_SEPARATOR, $class) . '.php';
include $filename;
}
}
library/SimplePie/Exception.php 0000644 00000001123 15143517255 0012553 0 ustar 00 data = $data;
}
/**
* Parse the input data
*
* @access public
* @return string Output data
*/
public function parse()
{
while (($position = strpos($this->data, '&', $this->position)) !== false) {
$this->position = $position;
$this->consume();
$this->entity();
$this->consumed = '';
}
return $this->data;
}
/**
* Consume the next byte
*
* @access private
* @return string|false The next byte, or false, if there is no more data
*/
public function consume()
{
if (isset($this->data[$this->position])) {
$this->consumed .= $this->data[$this->position];
return $this->data[$this->position++];
}
return false;
}
/**
* Consume a range of characters
*
* @access private
* @param string $chars Characters to consume
* @return string|false A series of characters that match the range, or false
*/
public function consume_range(string $chars)
{
if ($len = strspn($this->data, $chars, $this->position)) {
$data = substr($this->data, $this->position, $len);
$this->consumed .= $data;
$this->position += $len;
return $data;
}
return false;
}
/**
* Unconsume one byte
*
* @access private
* @return void
*/
public function unconsume()
{
$this->consumed = substr($this->consumed, 0, -1);
$this->position--;
}
/**
* Decode an entity
*
* @access private
* @return void
*/
public function entity()
{
switch ($this->consume()) {
case "\x09":
case "\x0A":
case "\x0B":
case "\x0C":
case "\x20":
case "\x3C":
case "\x26":
case false:
break;
case "\x23":
switch ($this->consume()) {
case "\x78":
case "\x58":
$range = '0123456789ABCDEFabcdef';
$hex = true;
break;
default:
$range = '0123456789';
$hex = false;
$this->unconsume();
break;
}
if ($codepoint = $this->consume_range($range)) {
static $windows_1252_specials = [0x0D => "\x0A", 0x80 => "\xE2\x82\xAC", 0x81 => "\xEF\xBF\xBD", 0x82 => "\xE2\x80\x9A", 0x83 => "\xC6\x92", 0x84 => "\xE2\x80\x9E", 0x85 => "\xE2\x80\xA6", 0x86 => "\xE2\x80\xA0", 0x87 => "\xE2\x80\xA1", 0x88 => "\xCB\x86", 0x89 => "\xE2\x80\xB0", 0x8A => "\xC5\xA0", 0x8B => "\xE2\x80\xB9", 0x8C => "\xC5\x92", 0x8D => "\xEF\xBF\xBD", 0x8E => "\xC5\xBD", 0x8F => "\xEF\xBF\xBD", 0x90 => "\xEF\xBF\xBD", 0x91 => "\xE2\x80\x98", 0x92 => "\xE2\x80\x99", 0x93 => "\xE2\x80\x9C", 0x94 => "\xE2\x80\x9D", 0x95 => "\xE2\x80\xA2", 0x96 => "\xE2\x80\x93", 0x97 => "\xE2\x80\x94", 0x98 => "\xCB\x9C", 0x99 => "\xE2\x84\xA2", 0x9A => "\xC5\xA1", 0x9B => "\xE2\x80\xBA", 0x9C => "\xC5\x93", 0x9D => "\xEF\xBF\xBD", 0x9E => "\xC5\xBE", 0x9F => "\xC5\xB8"];
if ($hex) {
// Cap to PHP_INT_MAX to ensure consistent behaviour if $codepoint is so large
// it cannot fit into int – just casting float to int might return junk (e.g. a negative number).
// If it is so large, `Misc::codepoint_to_utf8` will just return a replacement character.
$codepoint = (int) min(hexdec($codepoint), \PHP_INT_MAX);
} else {
// Casting string to int caps at PHP_INT_MAX automatically.
$codepoint = (int) $codepoint;
}
if (isset($windows_1252_specials[$codepoint])) {
$replacement = $windows_1252_specials[$codepoint];
} else {
$replacement = SimplePie_Misc::codepoint_to_utf8($codepoint);
}
if (!in_array($this->consume(), [';', false], true)) {
$this->unconsume();
}
$consumed_length = strlen($this->consumed);
$this->data = substr_replace($this->data, $replacement, $this->position - $consumed_length, $consumed_length);
$this->position += strlen($replacement) - $consumed_length;
}
break;
default:
static $entities = [
'Aacute' => "\xC3\x81",
'aacute' => "\xC3\xA1",
'Aacute;' => "\xC3\x81",
'aacute;' => "\xC3\xA1",
'Acirc' => "\xC3\x82",
'acirc' => "\xC3\xA2",
'Acirc;' => "\xC3\x82",
'acirc;' => "\xC3\xA2",
'acute' => "\xC2\xB4",
'acute;' => "\xC2\xB4",
'AElig' => "\xC3\x86",
'aelig' => "\xC3\xA6",
'AElig;' => "\xC3\x86",
'aelig;' => "\xC3\xA6",
'Agrave' => "\xC3\x80",
'agrave' => "\xC3\xA0",
'Agrave;' => "\xC3\x80",
'agrave;' => "\xC3\xA0",
'alefsym;' => "\xE2\x84\xB5",
'Alpha;' => "\xCE\x91",
'alpha;' => "\xCE\xB1",
'AMP' => "\x26",
'amp' => "\x26",
'AMP;' => "\x26",
'amp;' => "\x26",
'and;' => "\xE2\x88\xA7",
'ang;' => "\xE2\x88\xA0",
'apos;' => "\x27",
'Aring' => "\xC3\x85",
'aring' => "\xC3\xA5",
'Aring;' => "\xC3\x85",
'aring;' => "\xC3\xA5",
'asymp;' => "\xE2\x89\x88",
'Atilde' => "\xC3\x83",
'atilde' => "\xC3\xA3",
'Atilde;' => "\xC3\x83",
'atilde;' => "\xC3\xA3",
'Auml' => "\xC3\x84",
'auml' => "\xC3\xA4",
'Auml;' => "\xC3\x84",
'auml;' => "\xC3\xA4",
'bdquo;' => "\xE2\x80\x9E",
'Beta;' => "\xCE\x92",
'beta;' => "\xCE\xB2",
'brvbar' => "\xC2\xA6",
'brvbar;' => "\xC2\xA6",
'bull;' => "\xE2\x80\xA2",
'cap;' => "\xE2\x88\xA9",
'Ccedil' => "\xC3\x87",
'ccedil' => "\xC3\xA7",
'Ccedil;' => "\xC3\x87",
'ccedil;' => "\xC3\xA7",
'cedil' => "\xC2\xB8",
'cedil;' => "\xC2\xB8",
'cent' => "\xC2\xA2",
'cent;' => "\xC2\xA2",
'Chi;' => "\xCE\xA7",
'chi;' => "\xCF\x87",
'circ;' => "\xCB\x86",
'clubs;' => "\xE2\x99\xA3",
'cong;' => "\xE2\x89\x85",
'COPY' => "\xC2\xA9",
'copy' => "\xC2\xA9",
'COPY;' => "\xC2\xA9",
'copy;' => "\xC2\xA9",
'crarr;' => "\xE2\x86\xB5",
'cup;' => "\xE2\x88\xAA",
'curren' => "\xC2\xA4",
'curren;' => "\xC2\xA4",
'Dagger;' => "\xE2\x80\xA1",
'dagger;' => "\xE2\x80\xA0",
'dArr;' => "\xE2\x87\x93",
'darr;' => "\xE2\x86\x93",
'deg' => "\xC2\xB0",
'deg;' => "\xC2\xB0",
'Delta;' => "\xCE\x94",
'delta;' => "\xCE\xB4",
'diams;' => "\xE2\x99\xA6",
'divide' => "\xC3\xB7",
'divide;' => "\xC3\xB7",
'Eacute' => "\xC3\x89",
'eacute' => "\xC3\xA9",
'Eacute;' => "\xC3\x89",
'eacute;' => "\xC3\xA9",
'Ecirc' => "\xC3\x8A",
'ecirc' => "\xC3\xAA",
'Ecirc;' => "\xC3\x8A",
'ecirc;' => "\xC3\xAA",
'Egrave' => "\xC3\x88",
'egrave' => "\xC3\xA8",
'Egrave;' => "\xC3\x88",
'egrave;' => "\xC3\xA8",
'empty;' => "\xE2\x88\x85",
'emsp;' => "\xE2\x80\x83",
'ensp;' => "\xE2\x80\x82",
'Epsilon;' => "\xCE\x95",
'epsilon;' => "\xCE\xB5",
'equiv;' => "\xE2\x89\xA1",
'Eta;' => "\xCE\x97",
'eta;' => "\xCE\xB7",
'ETH' => "\xC3\x90",
'eth' => "\xC3\xB0",
'ETH;' => "\xC3\x90",
'eth;' => "\xC3\xB0",
'Euml' => "\xC3\x8B",
'euml' => "\xC3\xAB",
'Euml;' => "\xC3\x8B",
'euml;' => "\xC3\xAB",
'euro;' => "\xE2\x82\xAC",
'exist;' => "\xE2\x88\x83",
'fnof;' => "\xC6\x92",
'forall;' => "\xE2\x88\x80",
'frac12' => "\xC2\xBD",
'frac12;' => "\xC2\xBD",
'frac14' => "\xC2\xBC",
'frac14;' => "\xC2\xBC",
'frac34' => "\xC2\xBE",
'frac34;' => "\xC2\xBE",
'frasl;' => "\xE2\x81\x84",
'Gamma;' => "\xCE\x93",
'gamma;' => "\xCE\xB3",
'ge;' => "\xE2\x89\xA5",
'GT' => "\x3E",
'gt' => "\x3E",
'GT;' => "\x3E",
'gt;' => "\x3E",
'hArr;' => "\xE2\x87\x94",
'harr;' => "\xE2\x86\x94",
'hearts;' => "\xE2\x99\xA5",
'hellip;' => "\xE2\x80\xA6",
'Iacute' => "\xC3\x8D",
'iacute' => "\xC3\xAD",
'Iacute;' => "\xC3\x8D",
'iacute;' => "\xC3\xAD",
'Icirc' => "\xC3\x8E",
'icirc' => "\xC3\xAE",
'Icirc;' => "\xC3\x8E",
'icirc;' => "\xC3\xAE",
'iexcl' => "\xC2\xA1",
'iexcl;' => "\xC2\xA1",
'Igrave' => "\xC3\x8C",
'igrave' => "\xC3\xAC",
'Igrave;' => "\xC3\x8C",
'igrave;' => "\xC3\xAC",
'image;' => "\xE2\x84\x91",
'infin;' => "\xE2\x88\x9E",
'int;' => "\xE2\x88\xAB",
'Iota;' => "\xCE\x99",
'iota;' => "\xCE\xB9",
'iquest' => "\xC2\xBF",
'iquest;' => "\xC2\xBF",
'isin;' => "\xE2\x88\x88",
'Iuml' => "\xC3\x8F",
'iuml' => "\xC3\xAF",
'Iuml;' => "\xC3\x8F",
'iuml;' => "\xC3\xAF",
'Kappa;' => "\xCE\x9A",
'kappa;' => "\xCE\xBA",
'Lambda;' => "\xCE\x9B",
'lambda;' => "\xCE\xBB",
'lang;' => "\xE3\x80\x88",
'laquo' => "\xC2\xAB",
'laquo;' => "\xC2\xAB",
'lArr;' => "\xE2\x87\x90",
'larr;' => "\xE2\x86\x90",
'lceil;' => "\xE2\x8C\x88",
'ldquo;' => "\xE2\x80\x9C",
'le;' => "\xE2\x89\xA4",
'lfloor;' => "\xE2\x8C\x8A",
'lowast;' => "\xE2\x88\x97",
'loz;' => "\xE2\x97\x8A",
'lrm;' => "\xE2\x80\x8E",
'lsaquo;' => "\xE2\x80\xB9",
'lsquo;' => "\xE2\x80\x98",
'LT' => "\x3C",
'lt' => "\x3C",
'LT;' => "\x3C",
'lt;' => "\x3C",
'macr' => "\xC2\xAF",
'macr;' => "\xC2\xAF",
'mdash;' => "\xE2\x80\x94",
'micro' => "\xC2\xB5",
'micro;' => "\xC2\xB5",
'middot' => "\xC2\xB7",
'middot;' => "\xC2\xB7",
'minus;' => "\xE2\x88\x92",
'Mu;' => "\xCE\x9C",
'mu;' => "\xCE\xBC",
'nabla;' => "\xE2\x88\x87",
'nbsp' => "\xC2\xA0",
'nbsp;' => "\xC2\xA0",
'ndash;' => "\xE2\x80\x93",
'ne;' => "\xE2\x89\xA0",
'ni;' => "\xE2\x88\x8B",
'not' => "\xC2\xAC",
'not;' => "\xC2\xAC",
'notin;' => "\xE2\x88\x89",
'nsub;' => "\xE2\x8A\x84",
'Ntilde' => "\xC3\x91",
'ntilde' => "\xC3\xB1",
'Ntilde;' => "\xC3\x91",
'ntilde;' => "\xC3\xB1",
'Nu;' => "\xCE\x9D",
'nu;' => "\xCE\xBD",
'Oacute' => "\xC3\x93",
'oacute' => "\xC3\xB3",
'Oacute;' => "\xC3\x93",
'oacute;' => "\xC3\xB3",
'Ocirc' => "\xC3\x94",
'ocirc' => "\xC3\xB4",
'Ocirc;' => "\xC3\x94",
'ocirc;' => "\xC3\xB4",
'OElig;' => "\xC5\x92",
'oelig;' => "\xC5\x93",
'Ograve' => "\xC3\x92",
'ograve' => "\xC3\xB2",
'Ograve;' => "\xC3\x92",
'ograve;' => "\xC3\xB2",
'oline;' => "\xE2\x80\xBE",
'Omega;' => "\xCE\xA9",
'omega;' => "\xCF\x89",
'Omicron;' => "\xCE\x9F",
'omicron;' => "\xCE\xBF",
'oplus;' => "\xE2\x8A\x95",
'or;' => "\xE2\x88\xA8",
'ordf' => "\xC2\xAA",
'ordf;' => "\xC2\xAA",
'ordm' => "\xC2\xBA",
'ordm;' => "\xC2\xBA",
'Oslash' => "\xC3\x98",
'oslash' => "\xC3\xB8",
'Oslash;' => "\xC3\x98",
'oslash;' => "\xC3\xB8",
'Otilde' => "\xC3\x95",
'otilde' => "\xC3\xB5",
'Otilde;' => "\xC3\x95",
'otilde;' => "\xC3\xB5",
'otimes;' => "\xE2\x8A\x97",
'Ouml' => "\xC3\x96",
'ouml' => "\xC3\xB6",
'Ouml;' => "\xC3\x96",
'ouml;' => "\xC3\xB6",
'para' => "\xC2\xB6",
'para;' => "\xC2\xB6",
'part;' => "\xE2\x88\x82",
'permil;' => "\xE2\x80\xB0",
'perp;' => "\xE2\x8A\xA5",
'Phi;' => "\xCE\xA6",
'phi;' => "\xCF\x86",
'Pi;' => "\xCE\xA0",
'pi;' => "\xCF\x80",
'piv;' => "\xCF\x96",
'plusmn' => "\xC2\xB1",
'plusmn;' => "\xC2\xB1",
'pound' => "\xC2\xA3",
'pound;' => "\xC2\xA3",
'Prime;' => "\xE2\x80\xB3",
'prime;' => "\xE2\x80\xB2",
'prod;' => "\xE2\x88\x8F",
'prop;' => "\xE2\x88\x9D",
'Psi;' => "\xCE\xA8",
'psi;' => "\xCF\x88",
'QUOT' => "\x22",
'quot' => "\x22",
'QUOT;' => "\x22",
'quot;' => "\x22",
'radic;' => "\xE2\x88\x9A",
'rang;' => "\xE3\x80\x89",
'raquo' => "\xC2\xBB",
'raquo;' => "\xC2\xBB",
'rArr;' => "\xE2\x87\x92",
'rarr;' => "\xE2\x86\x92",
'rceil;' => "\xE2\x8C\x89",
'rdquo;' => "\xE2\x80\x9D",
'real;' => "\xE2\x84\x9C",
'REG' => "\xC2\xAE",
'reg' => "\xC2\xAE",
'REG;' => "\xC2\xAE",
'reg;' => "\xC2\xAE",
'rfloor;' => "\xE2\x8C\x8B",
'Rho;' => "\xCE\xA1",
'rho;' => "\xCF\x81",
'rlm;' => "\xE2\x80\x8F",
'rsaquo;' => "\xE2\x80\xBA",
'rsquo;' => "\xE2\x80\x99",
'sbquo;' => "\xE2\x80\x9A",
'Scaron;' => "\xC5\xA0",
'scaron;' => "\xC5\xA1",
'sdot;' => "\xE2\x8B\x85",
'sect' => "\xC2\xA7",
'sect;' => "\xC2\xA7",
'shy' => "\xC2\xAD",
'shy;' => "\xC2\xAD",
'Sigma;' => "\xCE\xA3",
'sigma;' => "\xCF\x83",
'sigmaf;' => "\xCF\x82",
'sim;' => "\xE2\x88\xBC",
'spades;' => "\xE2\x99\xA0",
'sub;' => "\xE2\x8A\x82",
'sube;' => "\xE2\x8A\x86",
'sum;' => "\xE2\x88\x91",
'sup;' => "\xE2\x8A\x83",
'sup1' => "\xC2\xB9",
'sup1;' => "\xC2\xB9",
'sup2' => "\xC2\xB2",
'sup2;' => "\xC2\xB2",
'sup3' => "\xC2\xB3",
'sup3;' => "\xC2\xB3",
'supe;' => "\xE2\x8A\x87",
'szlig' => "\xC3\x9F",
'szlig;' => "\xC3\x9F",
'Tau;' => "\xCE\xA4",
'tau;' => "\xCF\x84",
'there4;' => "\xE2\x88\xB4",
'Theta;' => "\xCE\x98",
'theta;' => "\xCE\xB8",
'thetasym;' => "\xCF\x91",
'thinsp;' => "\xE2\x80\x89",
'THORN' => "\xC3\x9E",
'thorn' => "\xC3\xBE",
'THORN;' => "\xC3\x9E",
'thorn;' => "\xC3\xBE",
'tilde;' => "\xCB\x9C",
'times' => "\xC3\x97",
'times;' => "\xC3\x97",
'TRADE;' => "\xE2\x84\xA2",
'trade;' => "\xE2\x84\xA2",
'Uacute' => "\xC3\x9A",
'uacute' => "\xC3\xBA",
'Uacute;' => "\xC3\x9A",
'uacute;' => "\xC3\xBA",
'uArr;' => "\xE2\x87\x91",
'uarr;' => "\xE2\x86\x91",
'Ucirc' => "\xC3\x9B",
'ucirc' => "\xC3\xBB",
'Ucirc;' => "\xC3\x9B",
'ucirc;' => "\xC3\xBB",
'Ugrave' => "\xC3\x99",
'ugrave' => "\xC3\xB9",
'Ugrave;' => "\xC3\x99",
'ugrave;' => "\xC3\xB9",
'uml' => "\xC2\xA8",
'uml;' => "\xC2\xA8",
'upsih;' => "\xCF\x92",
'Upsilon;' => "\xCE\xA5",
'upsilon;' => "\xCF\x85",
'Uuml' => "\xC3\x9C",
'uuml' => "\xC3\xBC",
'Uuml;' => "\xC3\x9C",
'uuml;' => "\xC3\xBC",
'weierp;' => "\xE2\x84\x98",
'Xi;' => "\xCE\x9E",
'xi;' => "\xCE\xBE",
'Yacute' => "\xC3\x9D",
'yacute' => "\xC3\xBD",
'Yacute;' => "\xC3\x9D",
'yacute;' => "\xC3\xBD",
'yen' => "\xC2\xA5",
'yen;' => "\xC2\xA5",
'yuml' => "\xC3\xBF",
'Yuml;' => "\xC5\xB8",
'yuml;' => "\xC3\xBF",
'Zeta;' => "\xCE\x96",
'zeta;' => "\xCE\xB6",
'zwj;' => "\xE2\x80\x8D",
'zwnj;' => "\xE2\x80\x8C"
];
for ($i = 0, $match = null; $i < 9 && $this->consume() !== false; $i++) {
// Cast for PHPStan on PHP < 8.0: We consumed as per the loop condition,
// so `$this->consumed` is non-empty and the substr offset is valid.
$consumed = (string) substr($this->consumed, 1);
if (isset($entities[$consumed])) {
$match = $consumed;
}
}
if ($match !== null) {
$this->data = substr_replace($this->data, $entities[$match], $this->position - strlen($consumed) - 1, strlen($match) + 1);
$this->position += strlen($entities[$match]) - strlen($consumed) - 1;
}
break;
}
}
}
library/SimplePie/gzdecode.php 0000644 00000001055 15143517255 0012405 0 ustar 00
*/
class SimplePie_HTTP_Parser extends Parser
{
}
}
library/SimplePie/XML/Declaration/Parser.php 0000644 00000001177 15143517255 0014747 0 ustar 00 */
public $cached_entities = [];
/** @var string */
public $http_base;
/** @var string */
public $base;
/** @var int */
public $base_location = 0;
/** @var int */
public $checked_feeds = 0;
/** @var int */
public $max_checked_feeds = 10;
/** @var bool */
public $force_fsockopen = false;
/** @var array */
public $curl_options = [];
/** @var ?\DomDocument */
public $dom;
/** @var ?Registry */
protected $registry;
/**
* @var Client|null
*/
private $http_client = null;
/**
* @param array $curl_options
*/
public function __construct(File $file, int $timeout = 10, ?string $useragent = null, int $max_checked_feeds = 10, bool $force_fsockopen = false, array $curl_options = [])
{
$this->file = $file;
$this->useragent = $useragent;
$this->timeout = $timeout;
$this->max_checked_feeds = $max_checked_feeds;
$this->force_fsockopen = $force_fsockopen;
$this->curl_options = $curl_options;
$body = $this->file->get_body_content();
if (class_exists('DOMDocument') && $body != '') {
$this->dom = new \DOMDocument();
set_error_handler([Misc::class, 'silence_errors']);
try {
$this->dom->loadHTML($body);
} catch (\Throwable $ex) {
$this->dom = null;
}
restore_error_handler();
} else {
$this->dom = null;
}
}
/**
* Set a PSR-18 client and PSR-17 factories
*
* Allows you to use your own HTTP client implementations.
*/
final public function set_http_client(
ClientInterface $http_client,
RequestFactoryInterface $request_factory,
UriFactoryInterface $uri_factory
): void {
$this->http_client = new Psr18Client($http_client, $request_factory, $uri_factory);
}
/**
* @return void
*/
public function set_registry(\SimplePie\Registry $registry)
{
$this->registry = $registry;
}
/**
* @param SimplePie::LOCATOR_* $type
* @param array|null $working
* @return Response|null
*/
public function find(int $type = \SimplePie\SimplePie::LOCATOR_ALL, ?array &$working = null)
{
assert($this->registry !== null);
if ($this->is_feed($this->file)) {
return $this->file;
}
if (Misc::is_remote_uri($this->file->get_final_requested_uri())) {
$sniffer = $this->registry->create(Content\Type\Sniffer::class, [$this->file]);
if ($sniffer->get_type() !== 'text/html') {
return null;
}
}
if ($type & ~\SimplePie\SimplePie::LOCATOR_NONE) {
$this->get_base();
}
if ($type & \SimplePie\SimplePie::LOCATOR_AUTODISCOVERY && $working = $this->autodiscovery()) {
return $working[0];
}
if ($type & (\SimplePie\SimplePie::LOCATOR_LOCAL_EXTENSION | \SimplePie\SimplePie::LOCATOR_LOCAL_BODY | \SimplePie\SimplePie::LOCATOR_REMOTE_EXTENSION | \SimplePie\SimplePie::LOCATOR_REMOTE_BODY) && $this->get_links()) {
if ($type & \SimplePie\SimplePie::LOCATOR_LOCAL_EXTENSION && $working = $this->extension($this->local)) {
return $working[0];
}
if ($type & \SimplePie\SimplePie::LOCATOR_LOCAL_BODY && $working = $this->body($this->local)) {
return $working[0];
}
if ($type & \SimplePie\SimplePie::LOCATOR_REMOTE_EXTENSION && $working = $this->extension($this->elsewhere)) {
return $working[0];
}
if ($type & \SimplePie\SimplePie::LOCATOR_REMOTE_BODY && $working = $this->body($this->elsewhere)) {
return $working[0];
}
}
return null;
}
/**
* @return bool
*/
public function is_feed(Response $file, bool $check_html = false)
{
assert($this->registry !== null);
if (Misc::is_remote_uri($file->get_final_requested_uri())) {
$sniffer = $this->registry->create(Content\Type\Sniffer::class, [$file]);
$sniffed = $sniffer->get_type();
$mime_types = ['application/rss+xml', 'application/rdf+xml',
'text/rdf', 'application/atom+xml', 'text/xml',
'application/xml', 'application/x-rss+xml'];
if ($check_html) {
$mime_types[] = 'text/html';
}
return in_array($sniffed, $mime_types);
} elseif (is_file($file->get_final_requested_uri())) {
return true;
} else {
return false;
}
}
/**
* @return void
*/
public function get_base()
{
assert($this->registry !== null);
if ($this->dom === null) {
throw new \SimplePie\Exception('DOMDocument not found, unable to use locator');
}
$this->http_base = $this->file->get_final_requested_uri();
$this->base = $this->http_base;
$elements = $this->dom->getElementsByTagName('base');
foreach ($elements as $element) {
if ($element->hasAttribute('href')) {
$base = $this->registry->call(Misc::class, 'absolutize_url', [trim($element->getAttribute('href')), $this->http_base]);
if ($base === false) {
continue;
}
$this->base = $base;
$this->base_location = method_exists($element, 'getLineNo') ? $element->getLineNo() : 0;
break;
}
}
}
/**
* @return array|null
*/
public function autodiscovery()
{
$done = [];
$feeds = [];
$feeds = array_merge($feeds, $this->search_elements_by_tag('link', $done, $feeds));
$feeds = array_merge($feeds, $this->search_elements_by_tag('a', $done, $feeds));
$feeds = array_merge($feeds, $this->search_elements_by_tag('area', $done, $feeds));
if (!empty($feeds)) {
return array_values($feeds);
}
return null;
}
/**
* @param string[] $done
* @param array $feeds
* @return array
*/
protected function search_elements_by_tag(string $name, array &$done, array $feeds)
{
assert($this->registry !== null);
if ($this->dom === null) {
throw new \SimplePie\Exception('DOMDocument not found, unable to use locator');
}
$links = $this->dom->getElementsByTagName($name);
foreach ($links as $link) {
if ($this->checked_feeds === $this->max_checked_feeds) {
break;
}
if ($link->hasAttribute('href') && $link->hasAttribute('rel')) {
$rel = array_unique($this->registry->call(Misc::class, 'space_separated_tokens', [strtolower($link->getAttribute('rel'))]));
$line = method_exists($link, 'getLineNo') ? $link->getLineNo() : 1;
if ($this->base_location < $line) {
$href = $this->registry->call(Misc::class, 'absolutize_url', [trim($link->getAttribute('href')), $this->base]);
} else {
$href = $this->registry->call(Misc::class, 'absolutize_url', [trim($link->getAttribute('href')), $this->http_base]);
}
if ($href === false) {
continue;
}
if (!in_array($href, $done) && in_array('feed', $rel) || (in_array('alternate', $rel) && !in_array('stylesheet', $rel) && $link->hasAttribute('type') && in_array(strtolower($this->registry->call(Misc::class, 'parse_mime', [$link->getAttribute('type')])), ['text/html', 'application/rss+xml', 'application/atom+xml'])) && !isset($feeds[$href])) {
$this->checked_feeds++;
$headers = [
'Accept' => SimplePie::DEFAULT_HTTP_ACCEPT_HEADER,
];
try {
$feed = $this->get_http_client()->request(Client::METHOD_GET, $href, $headers);
if ((!Misc::is_remote_uri($feed->get_final_requested_uri()) || ($feed->get_status_code() === 200 || $feed->get_status_code() > 206 && $feed->get_status_code() < 300)) && $this->is_feed($feed, true)) {
$feeds[$href] = $feed;
}
} catch (ClientException $th) {
// Just mark it as done and continue.
}
}
$done[] = $href;
}
}
return $feeds;
}
/**
* @return true|null
*/
public function get_links()
{
assert($this->registry !== null);
if ($this->dom === null) {
throw new \SimplePie\Exception('DOMDocument not found, unable to use locator');
}
$links = $this->dom->getElementsByTagName('a');
foreach ($links as $link) {
if ($link->hasAttribute('href')) {
$href = trim($link->getAttribute('href'));
$parsed = $this->registry->call(Misc::class, 'parse_url', [$href]);
if ($parsed['scheme'] === '' || preg_match('/^(https?|feed)?$/i', $parsed['scheme'])) {
if (method_exists($link, 'getLineNo') && $this->base_location < $link->getLineNo()) {
$href = $this->registry->call(Misc::class, 'absolutize_url', [trim($link->getAttribute('href')), $this->base]);
} else {
$href = $this->registry->call(Misc::class, 'absolutize_url', [trim($link->getAttribute('href')), $this->http_base]);
}
if ($href === false) {
continue;
}
$current = $this->registry->call(Misc::class, 'parse_url', [$this->file->get_final_requested_uri()]);
if ($parsed['authority'] === '' || $parsed['authority'] === $current['authority']) {
$this->local[] = $href;
} else {
$this->elsewhere[] = $href;
}
}
}
}
$this->local = array_unique($this->local);
$this->elsewhere = array_unique($this->elsewhere);
if (!empty($this->local) || !empty($this->elsewhere)) {
return true;
}
return null;
}
/**
* Extracts first `link` element with given `rel` attribute inside the `head` element.
*
* @return string|null
*/
public function get_rel_link(string $rel)
{
assert($this->registry !== null);
if ($this->dom === null) {
throw new \SimplePie\Exception('DOMDocument not found, unable to use '.
'locator');
}
if (!class_exists('DOMXpath')) {
throw new \SimplePie\Exception('DOMXpath not found, unable to use '.
'get_rel_link');
}
$xpath = new \DOMXpath($this->dom);
$query = '(//head)[1]/link[@rel and @href]';
/** @var \DOMNodeList<\DOMElement> */
$queryResult = $xpath->query($query);
foreach ($queryResult as $link) {
$href = trim($link->getAttribute('href'));
$parsed = $this->registry->call(Misc::class, 'parse_url', [$href]);
if ($parsed['scheme'] === '' ||
preg_match('/^https?$/i', $parsed['scheme'])) {
if (method_exists($link, 'getLineNo') &&
$this->base_location < $link->getLineNo()) {
$href = $this->registry->call(
Misc::class,
'absolutize_url',
[trim($link->getAttribute('href')), $this->base]
);
} else {
$href = $this->registry->call(
Misc::class,
'absolutize_url',
[trim($link->getAttribute('href')), $this->http_base]
);
}
if ($href === false) {
return null;
}
$rel_values = explode(' ', strtolower($link->getAttribute('rel')));
if (in_array($rel, $rel_values)) {
return $href;
}
}
}
return null;
}
/**
* @param string[] $array
* @return array|null
*/
public function extension(array &$array)
{
foreach ($array as $key => $value) {
if ($this->checked_feeds === $this->max_checked_feeds) {
break;
}
$extension = strrchr($value, '.');
if ($extension !== false && in_array(strtolower($extension), ['.rss', '.rdf', '.atom', '.xml'])) {
$this->checked_feeds++;
$headers = [
'Accept' => SimplePie::DEFAULT_HTTP_ACCEPT_HEADER,
];
try {
$feed = $this->get_http_client()->request(Client::METHOD_GET, $value, $headers);
if ((!Misc::is_remote_uri($feed->get_final_requested_uri()) || ($feed->get_status_code() === 200 || $feed->get_status_code() > 206 && $feed->get_status_code() < 300)) && $this->is_feed($feed)) {
return [$feed];
}
} catch (ClientException $th) {
// Just unset and continue.
}
unset($array[$key]);
}
}
return null;
}
/**
* @param string[] $array
* @return array|null
*/
public function body(array &$array)
{
foreach ($array as $key => $value) {
if ($this->checked_feeds === $this->max_checked_feeds) {
break;
}
if (preg_match('/(feed|rss|rdf|atom|xml)/i', $value)) {
$this->checked_feeds++;
$headers = [
'Accept' => SimplePie::DEFAULT_HTTP_ACCEPT_HEADER,
];
try {
$feed = $this->get_http_client()->request(Client::METHOD_GET, $value, $headers);
if ((!Misc::is_remote_uri($feed->get_final_requested_uri()) || ($feed->get_status_code() === 200 || $feed->get_status_code() > 206 && $feed->get_status_code() < 300)) && $this->is_feed($feed)) {
return [$feed];
}
} catch (ClientException $th) {
// Just unset and continue.
}
unset($array[$key]);
}
}
return null;
}
/**
* Get a HTTP client
*/
private function get_http_client(): Client
{
assert($this->registry !== null);
if ($this->http_client === null) {
$options = [
'timeout' => $this->timeout,
'redirects' => 5,
'force_fsockopen' => $this->force_fsockopen,
'curl_options' => $this->curl_options,
];
if ($this->useragent !== null) {
$options['useragent'] = $this->useragent;
}
return new FileClient(
$this->registry,
$options
);
}
return $this->http_client;
}
}
class_alias('SimplePie\Locator', 'SimplePie_Locator', false);
src/Gzdecode.php 0000644 00000020500 15143517255 0007575 0 ustar 00 compressed_data = $data;
$this->compressed_size = strlen($data);
}
/**
* Decode the GZIP stream
*
* @return bool Successfulness
*/
public function parse()
{
if ($this->compressed_size >= $this->min_compressed_size) {
$len = 0;
// Check ID1, ID2, and CM
if (substr($this->compressed_data, 0, 3) !== "\x1F\x8B\x08") {
return false;
}
// Get the FLG (FLaGs)
$this->flags = ord($this->compressed_data[3]);
// FLG bits above (1 << 4) are reserved
if ($this->flags > 0x1F) {
return false;
}
// Advance the pointer after the above
$this->position += 4;
// MTIME
$mtime = substr($this->compressed_data, $this->position, 4);
// Reverse the string if we're on a big-endian arch because l is the only signed long and is machine endianness
if (current((array) unpack('S', "\x00\x01")) === 1) {
$mtime = strrev($mtime);
}
$this->MTIME = current((array) unpack('l', $mtime));
$this->position += 4;
// Get the XFL (eXtra FLags)
$this->XFL = ord($this->compressed_data[$this->position++]);
// Get the OS (Operating System)
$this->OS = ord($this->compressed_data[$this->position++]);
// Parse the FEXTRA
if ($this->flags & 4) {
// Read subfield IDs
$this->SI1 = $this->compressed_data[$this->position++];
$this->SI2 = $this->compressed_data[$this->position++];
// SI2 set to zero is reserved for future use
if ($this->SI2 === "\x00") {
return false;
}
// Get the length of the extra field
$len = current((array) unpack('v', substr($this->compressed_data, $this->position, 2)));
$this->position += 2;
// Check the length of the string is still valid
$this->min_compressed_size += $len + 4;
if ($this->compressed_size >= $this->min_compressed_size) {
// Set the extra field to the given data
$this->extra_field = substr($this->compressed_data, $this->position, $len);
$this->position += $len;
} else {
return false;
}
}
// Parse the FNAME
if ($this->flags & 8) {
// Get the length of the filename
$len = strcspn($this->compressed_data, "\x00", $this->position);
// Check the length of the string is still valid
$this->min_compressed_size += $len + 1;
if ($this->compressed_size >= $this->min_compressed_size) {
// Set the original filename to the given string
$this->filename = substr($this->compressed_data, $this->position, $len);
$this->position += $len + 1;
} else {
return false;
}
}
// Parse the FCOMMENT
if ($this->flags & 16) {
// Get the length of the comment
$len = strcspn($this->compressed_data, "\x00", $this->position);
// Check the length of the string is still valid
$this->min_compressed_size += $len + 1;
if ($this->compressed_size >= $this->min_compressed_size) {
// Set the original comment to the given string
$this->comment = substr($this->compressed_data, $this->position, $len);
$this->position += $len + 1;
} else {
return false;
}
}
// Parse the FHCRC
if ($this->flags & 2) {
// Check the length of the string is still valid
$this->min_compressed_size += $len + 2;
if ($this->compressed_size >= $this->min_compressed_size) {
// Read the CRC
$crc = current((array) unpack('v', substr($this->compressed_data, $this->position, 2)));
// Check the CRC matches
if ((crc32(substr($this->compressed_data, 0, $this->position)) & 0xFFFF) === $crc) {
$this->position += 2;
} else {
return false;
}
} else {
return false;
}
}
// Decompress the actual data
if (($data = gzinflate(substr($this->compressed_data, $this->position, -8))) === false) {
return false;
}
$this->data = $data;
$this->position = $this->compressed_size - 8;
// Check CRC of data
$crc = current((array) unpack('V', substr($this->compressed_data, $this->position, 4)));
$this->position += 4;
/*if (extension_loaded('hash') && sprintf('%u', current(unpack('V', hash('crc32b', $this->data)))) !== sprintf('%u', $crc))
{
return false;
}*/
// Check ISIZE of data
$isize = current((array) unpack('V', substr($this->compressed_data, $this->position, 4)));
$this->position += 4;
if (sprintf('%u', strlen($this->data) & 0xFFFFFFFF) !== sprintf('%u', $isize)) {
return false;
}
// Wow, against all odds, we've actually got a valid gzip string
return true;
}
return false;
}
}
class_alias('SimplePie\Gzdecode', 'SimplePie_gzdecode');
src/Parse/Date.php 0000644 00000062206 15143517255 0010011 0 ustar 00 ordinal day number in the week
*
* @access protected
* @var array>
*/
public $day = [
// English
'mon' => 1,
'monday' => 1,
'tue' => 2,
'tuesday' => 2,
'wed' => 3,
'wednesday' => 3,
'thu' => 4,
'thursday' => 4,
'fri' => 5,
'friday' => 5,
'sat' => 6,
'saturday' => 6,
'sun' => 7,
'sunday' => 7,
// Dutch
'maandag' => 1,
'dinsdag' => 2,
'woensdag' => 3,
'donderdag' => 4,
'vrijdag' => 5,
'zaterdag' => 6,
'zondag' => 7,
// French
'lundi' => 1,
'mardi' => 2,
'mercredi' => 3,
'jeudi' => 4,
'vendredi' => 5,
'samedi' => 6,
'dimanche' => 7,
// German
'montag' => 1,
'mo' => 1,
'dienstag' => 2,
'di' => 2,
'mittwoch' => 3,
'mi' => 3,
'donnerstag' => 4,
'do' => 4,
'freitag' => 5,
'fr' => 5,
'samstag' => 6,
'sa' => 6,
'sonnabend' => 6,
// AFAIK no short form for sonnabend
'so' => 7,
'sonntag' => 7,
// Italian
'lunedì' => 1,
'martedì' => 2,
'mercoledì' => 3,
'giovedì' => 4,
'venerdì' => 5,
'sabato' => 6,
'domenica' => 7,
// Spanish
'lunes' => 1,
'martes' => 2,
'miércoles' => 3,
'jueves' => 4,
'viernes' => 5,
'sábado' => 6,
'domingo' => 7,
// Finnish
'maanantai' => 1,
'tiistai' => 2,
'keskiviikko' => 3,
'torstai' => 4,
'perjantai' => 5,
'lauantai' => 6,
'sunnuntai' => 7,
// Hungarian
'hétfő' => 1,
'kedd' => 2,
'szerda' => 3,
'csütörtok' => 4,
'péntek' => 5,
'szombat' => 6,
'vasárnap' => 7,
// Greek
'Δευ' => 1,
'Τρι' => 2,
'Τετ' => 3,
'Πεμ' => 4,
'Παρ' => 5,
'Σαβ' => 6,
'Κυρ' => 7,
// Russian
'Пн.' => 1,
'Вт.' => 2,
'Ср.' => 3,
'Чт.' => 4,
'Пт.' => 5,
'Сб.' => 6,
'Вс.' => 7,
];
/**
* List of months, calendar month name => calendar month number
*
* @access protected
* @var array>
*/
public $month = [
// English
'jan' => 1,
'january' => 1,
'feb' => 2,
'february' => 2,
'mar' => 3,
'march' => 3,
'apr' => 4,
'april' => 4,
'may' => 5,
// No long form of May
'jun' => 6,
'june' => 6,
'jul' => 7,
'july' => 7,
'aug' => 8,
'august' => 8,
'sep' => 9,
'september' => 9,
'oct' => 10,
'october' => 10,
'nov' => 11,
'november' => 11,
'dec' => 12,
'december' => 12,
// Dutch
'januari' => 1,
'februari' => 2,
'maart' => 3,
// 'april' => 4,
'mei' => 5,
'juni' => 6,
'juli' => 7,
'augustus' => 8,
// 'september' => 9,
'oktober' => 10,
// 'november' => 11,
// 'december' => 12,
// French
'janvier' => 1,
'février' => 2,
'mars' => 3,
'avril' => 4,
'mai' => 5,
'juin' => 6,
'juillet' => 7,
'août' => 8,
'septembre' => 9,
'octobre' => 10,
'novembre' => 11,
'décembre' => 12,
// German
'januar' => 1,
// 'jan' => 1,
'februar' => 2,
// 'feb' => 2,
'märz' => 3,
'mär' => 3,
// 'april' => 4,
// 'apr' => 4,
// 'mai' => 5, // no short form for may
// 'juni' => 6,
// 'jun' => 6,
// 'juli' => 7,
// 'jul' => 7,
// 'august' => 8,
// 'aug' => 8,
// 'september' => 9,
// 'sep' => 9,
// 'oktober' => 10,
'okt' => 10,
// 'november' => 11,
// 'nov' => 11,
'dezember' => 12,
'dez' => 12,
// Italian
'gennaio' => 1,
'febbraio' => 2,
'marzo' => 3,
'aprile' => 4,
'maggio' => 5,
'giugno' => 6,
'luglio' => 7,
'agosto' => 8,
'settembre' => 9,
'ottobre' => 10,
// 'novembre' => 11,
'dicembre' => 12,
// Spanish
'enero' => 1,
'febrero' => 2,
// 'marzo' => 3,
'abril' => 4,
'mayo' => 5,
'junio' => 6,
'julio' => 7,
// 'agosto' => 8,
'septiembre' => 9,
'setiembre' => 9,
'octubre' => 10,
'noviembre' => 11,
'diciembre' => 12,
// Finnish
'tammikuu' => 1,
'helmikuu' => 2,
'maaliskuu' => 3,
'huhtikuu' => 4,
'toukokuu' => 5,
'kesäkuu' => 6,
'heinäkuu' => 7,
'elokuu' => 8,
'suuskuu' => 9,
'lokakuu' => 10,
'marras' => 11,
'joulukuu' => 12,
// Hungarian
'január' => 1,
'február' => 2,
'március' => 3,
'április' => 4,
'május' => 5,
'június' => 6,
'július' => 7,
'augusztus' => 8,
'szeptember' => 9,
'október' => 10,
// 'november' => 11,
// 'december' => 12,
// Greek
'Ιαν' => 1,
'Φεβ' => 2,
'Μάώ' => 3,
'Μαώ' => 3,
'Απρ' => 4,
'Μάι' => 5,
'Μαϊ' => 5,
'Μαι' => 5,
'Ιούν' => 6,
'Ιον' => 6,
'Ιούλ' => 7,
'Ιολ' => 7,
'Αύγ' => 8,
'Αυγ' => 8,
'Σεπ' => 9,
'Οκτ' => 10,
'Νοέ' => 11,
'Δεκ' => 12,
// Russian
'Янв' => 1,
'января' => 1,
'Фев' => 2,
'февраля' => 2,
'Мар' => 3,
'марта' => 3,
'Апр' => 4,
'апреля' => 4,
'Май' => 5,
'мая' => 5,
'Июн' => 6,
'июня' => 6,
'Июл' => 7,
'июля' => 7,
'Авг' => 8,
'августа' => 8,
'Сен' => 9,
'сентября' => 9,
'Окт' => 10,
'октября' => 10,
'Ноя' => 11,
'ноября' => 11,
'Дек' => 12,
'декабря' => 12,
];
/**
* List of timezones, abbreviation => offset from UTC
*
* @access protected
* @var array
*/
public $timezone = [
'ACDT' => 37800,
'ACIT' => 28800,
'ACST' => 34200,
'ACT' => -18000,
'ACWDT' => 35100,
'ACWST' => 31500,
'AEDT' => 39600,
'AEST' => 36000,
'AFT' => 16200,
'AKDT' => -28800,
'AKST' => -32400,
'AMDT' => 18000,
'AMT' => -14400,
'ANAST' => 46800,
'ANAT' => 43200,
'ART' => -10800,
'AZOST' => -3600,
'AZST' => 18000,
'AZT' => 14400,
'BIOT' => 21600,
'BIT' => -43200,
'BOT' => -14400,
'BRST' => -7200,
'BRT' => -10800,
'BST' => 3600,
'BTT' => 21600,
'CAST' => 18000,
'CAT' => 7200,
'CCT' => 23400,
'CDT' => -18000,
'CEDT' => 7200,
'CEST' => 7200,
'CET' => 3600,
'CGST' => -7200,
'CGT' => -10800,
'CHADT' => 49500,
'CHAST' => 45900,
'CIST' => -28800,
'CKT' => -36000,
'CLDT' => -10800,
'CLST' => -14400,
'COT' => -18000,
'CST' => -21600,
'CVT' => -3600,
'CXT' => 25200,
'DAVT' => 25200,
'DTAT' => 36000,
'EADT' => -18000,
'EAST' => -21600,
'EAT' => 10800,
'ECT' => -18000,
'EDT' => -14400,
'EEST' => 10800,
'EET' => 7200,
'EGT' => -3600,
'EKST' => 21600,
'EST' => -18000,
'FJT' => 43200,
'FKDT' => -10800,
'FKST' => -14400,
'FNT' => -7200,
'GALT' => -21600,
'GEDT' => 14400,
'GEST' => 10800,
'GFT' => -10800,
'GILT' => 43200,
'GIT' => -32400,
'GST' => 14400,
// 'GST' => -7200,
'GYT' => -14400,
'HAA' => -10800,
'HAC' => -18000,
'HADT' => -32400,
'HAE' => -14400,
'HAP' => -25200,
'HAR' => -21600,
'HAST' => -36000,
'HAT' => -9000,
'HAY' => -28800,
'HKST' => 28800,
'HMT' => 18000,
'HNA' => -14400,
'HNC' => -21600,
'HNE' => -18000,
'HNP' => -28800,
'HNR' => -25200,
'HNT' => -12600,
'HNY' => -32400,
'IRDT' => 16200,
'IRKST' => 32400,
'IRKT' => 28800,
'IRST' => 12600,
'JFDT' => -10800,
'JFST' => -14400,
'JST' => 32400,
'KGST' => 21600,
'KGT' => 18000,
'KOST' => 39600,
'KOVST' => 28800,
'KOVT' => 25200,
'KRAST' => 28800,
'KRAT' => 25200,
'KST' => 32400,
'LHDT' => 39600,
'LHST' => 37800,
'LINT' => 50400,
'LKT' => 21600,
'MAGST' => 43200,
'MAGT' => 39600,
'MAWT' => 21600,
'MDT' => -21600,
'MESZ' => 7200,
'MEZ' => 3600,
'MHT' => 43200,
'MIT' => -34200,
'MNST' => 32400,
'MSDT' => 14400,
'MSST' => 10800,
'MST' => -25200,
'MUT' => 14400,
'MVT' => 18000,
'MYT' => 28800,
'NCT' => 39600,
'NDT' => -9000,
'NFT' => 41400,
'NMIT' => 36000,
'NOVST' => 25200,
'NOVT' => 21600,
'NPT' => 20700,
'NRT' => 43200,
'NST' => -12600,
'NUT' => -39600,
'NZDT' => 46800,
'NZST' => 43200,
'OMSST' => 25200,
'OMST' => 21600,
'PDT' => -25200,
'PET' => -18000,
'PETST' => 46800,
'PETT' => 43200,
'PGT' => 36000,
'PHOT' => 46800,
'PHT' => 28800,
'PKT' => 18000,
'PMDT' => -7200,
'PMST' => -10800,
'PONT' => 39600,
'PST' => -28800,
'PWT' => 32400,
'PYST' => -10800,
'PYT' => -14400,
'RET' => 14400,
'ROTT' => -10800,
'SAMST' => 18000,
'SAMT' => 14400,
'SAST' => 7200,
'SBT' => 39600,
'SCDT' => 46800,
'SCST' => 43200,
'SCT' => 14400,
'SEST' => 3600,
'SGT' => 28800,
'SIT' => 28800,
'SRT' => -10800,
'SST' => -39600,
'SYST' => 10800,
'SYT' => 7200,
'TFT' => 18000,
'THAT' => -36000,
'TJT' => 18000,
'TKT' => -36000,
'TMT' => 18000,
'TOT' => 46800,
'TPT' => 32400,
'TRUT' => 36000,
'TVT' => 43200,
'TWT' => 28800,
'UYST' => -7200,
'UYT' => -10800,
'UZT' => 18000,
'VET' => -14400,
'VLAST' => 39600,
'VLAT' => 36000,
'VOST' => 21600,
'VUT' => 39600,
'WAST' => 7200,
'WAT' => 3600,
'WDT' => 32400,
'WEST' => 3600,
'WFT' => 43200,
'WIB' => 25200,
'WIT' => 32400,
'WITA' => 28800,
'WKST' => 18000,
'WST' => 28800,
'YAKST' => 36000,
'YAKT' => 32400,
'YAPT' => 36000,
'YEKST' => 21600,
'YEKT' => 18000,
];
/**
* Cached PCRE for Date::$day
*
* @access protected
* @var string
*/
public $day_pcre;
/**
* Cached PCRE for Date::$month
*
* @access protected
* @var string
*/
public $month_pcre;
/**
* Array of user-added callback methods
*
* @access private
* @var array
*/
public $built_in = [];
/**
* Array of user-added callback methods
*
* @access private
* @var array
*/
public $user = [];
/**
* Create new Date object, and set self::day_pcre,
* self::month_pcre, and self::built_in
*
* @access private
*/
public function __construct()
{
$this->day_pcre = '(' . implode('|', array_keys($this->day)) . ')';
$this->month_pcre = '(' . implode('|', array_keys($this->month)) . ')';
static $cache;
if (!isset($cache[get_class($this)])) {
$all_methods = get_class_methods($this);
foreach ($all_methods as $method) {
if (strtolower(substr($method, 0, 5)) === 'date_') {
$cache[get_class($this)][] = $method;
}
}
}
foreach ($cache[get_class($this)] as $method) {
$this->built_in[] = $method;
}
}
/**
* Get the object
*
* @access public
* @return Date
*/
public static function get()
{
static $object;
if (!$object) {
$object = new Date();
}
return $object;
}
/**
* Parse a date
*
* @final
* @access public
* @param string $date Date to parse
* @return int|false Timestamp corresponding to date string, or false on failure
*/
public function parse(string $date)
{
foreach ($this->user as $method) {
if (($returned = call_user_func($method, $date)) !== false) {
return (int) $returned;
}
}
foreach ($this->built_in as $method) {
// TODO: we should really check this in constructor but that would require private properties.
/** @var callable(string): (int|false) */
$callable = [$this, $method];
if (($returned = call_user_func($callable, $date)) !== false) {
return $returned;
}
}
return false;
}
/**
* Add a callback method to parse a date
*
* @final
* @access public
* @param callable $callback
* @return void
*/
public function add_callback(callable $callback)
{
$this->user[] = $callback;
}
/**
* Parse a superset of W3C-DTF (allows hyphens and colons to be omitted, as
* well as allowing any of upper or lower case "T", horizontal tabs, or
* spaces to be used as the time separator (including more than one))
*
* @access protected
* @param string $date
* @return int|false Timestamp
*/
public function date_w3cdtf(string $date)
{
$pcre = <<<'PCRE'
/
^
(?P[0-9]{4})
(?:
-?
(?P[0-9]{2})
(?:
-?
(?P[0-9]{2})
(?:
[Tt\x09\x20]+
(?P[0-9]{2})
(?:
:?
(?P[0-9]{2})
(?:
:?
(?P[0-9]{2})
(?:
.
(?P[0-9]*)
)?
)?
)?
(?:
(?PZ)
| (?P[+\-])
(?P[0-9]{1,2})
:?
(?P[0-9]{1,2})
)
)?
)?
)?
$
/x
PCRE;
if (preg_match($pcre, $date, $match)) {
// Fill in empty matches and convert to proper types.
$year = (int) $match['year'];
$month = isset($match['month']) ? (int) $match['month'] : 1;
$day = isset($match['day']) ? (int) $match['day'] : 1;
$hour = isset($match['hour']) ? (int) $match['hour'] : 0;
$minute = isset($match['minute']) ? (int) $match['minute'] : 0;
$second = isset($match['second']) ? (int) $match['second'] : 0;
$second_fraction = isset($match['second_fraction']) ? ((int) $match['second_fraction']) / (10 ** strlen($match['second_fraction'])) : 0;
$tz_sign = ($match['tz_sign'] ?? '') === '-' ? -1 : 1;
$tz_hour = isset($match['tz_hour']) ? (int) $match['tz_hour'] : 0;
$tz_minute = isset($match['tz_minute']) ? (int) $match['tz_minute'] : 0;
// Numeric timezone
$timezone = $tz_hour * 3600;
$timezone += $tz_minute * 60;
$timezone *= $tz_sign;
// Convert the number of seconds to an integer, taking decimals into account
$second = (int) round($second + $second_fraction);
return gmmktime($hour, $minute, $second, $month, $day, $year) - $timezone;
}
return false;
}
/**
* Remove RFC822 comments
*
* @access protected
* @param string $string Data to strip comments from
* @return string Comment stripped string
*/
public function remove_rfc2822_comments(string $string)
{
$position = 0;
$length = strlen($string);
$depth = 0;
$output = '';
while ($position < $length && ($pos = strpos($string, '(', $position)) !== false) {
$output .= substr($string, $position, $pos - $position);
$position = $pos + 1;
if ($pos === 0 || $string[$pos - 1] !== '\\') {
$depth++;
while ($depth && $position < $length) {
$position += strcspn($string, '()', $position);
if ($string[$position - 1] === '\\') {
$position++;
continue;
} elseif (isset($string[$position])) {
switch ($string[$position]) {
case '(':
$depth++;
break;
case ')':
$depth--;
break;
}
$position++;
} else {
break;
}
}
} else {
$output .= '(';
}
}
$output .= substr($string, $position);
return $output;
}
/**
* Parse RFC2822's date format
*
* @access protected
* @param string $date
* @return int|false Timestamp
*/
public function date_rfc2822(string $date)
{
static $pcre;
if (!$pcre) {
$wsp = '[\x09\x20]';
$fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
$optional_fws = $fws . '?';
$day_name = $this->day_pcre;
$month = $this->month_pcre;
$day = '([0-9]{1,2})';
$hour = $minute = $second = '([0-9]{2})';
$year = '([0-9]{2,4})';
$num_zone = '([+\-])([0-9]{2})([0-9]{2})';
$character_zone = '([A-Z]{1,5})';
$zone = '(?:' . $num_zone . '|' . $character_zone . ')';
$pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i';
}
if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match)) {
/*
Capturing subpatterns:
1: Day name
2: Day
3: Month
4: Year
5: Hour
6: Minute
7: Second
8: Timezone ±
9: Timezone hours
10: Timezone minutes
11: Alphabetic timezone
*/
$day = (int) $match[2];
// Find the month number
$month = $this->month[strtolower($match[3])];
$year = (int) $match[4];
$hour = (int) $match[5];
$minute = (int) $match[6];
// Second is optional, if it is empty set it to zero
$second = (int) $match[7];
$tz_sign = $match[8];
$tz_hour = (int) $match[9];
$tz_minute = (int) $match[10];
$tz_code = isset($match[11]) ? strtoupper($match[11]) : '';
// Numeric timezone
if ($tz_sign !== '') {
$timezone = $tz_hour * 3600;
$timezone += $tz_minute * 60;
if ($tz_sign === '-') {
$timezone = 0 - $timezone;
}
}
// Character timezone
elseif (isset($this->timezone[$tz_code])) {
$timezone = $this->timezone[$tz_code];
}
// Assume everything else to be -0000
else {
$timezone = 0;
}
// Deal with 2/3 digit years
if ($year < 50) {
$year += 2000;
} elseif ($year < 1000) {
$year += 1900;
}
return gmmktime($hour, $minute, $second, $month, $day, $year) - $timezone;
}
return false;
}
/**
* Parse RFC850's date format
*
* @access protected
* @param string $date
* @return int|false Timestamp
*/
public function date_rfc850(string $date)
{
static $pcre;
if (!$pcre) {
$space = '[\x09\x20]+';
$day_name = $this->day_pcre;
$month = $this->month_pcre;
$day = '([0-9]{1,2})';
$year = $hour = $minute = $second = '([0-9]{2})';
$zone = '([A-Z]{1,5})';
$pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
}
if (preg_match($pcre, $date, $match)) {
/*
Capturing subpatterns:
1: Day name
2: Day
3: Month
4: Year
5: Hour
6: Minute
7: Second
8: Timezone
*/
$day = (int) $match[2];
// Month
$month = $this->month[strtolower($match[3])];
$year = (int) $match[4];
$hour = (int) $match[5];
$minute = (int) $match[6];
// Second is optional, if it is empty set it to zero
$second = (int) $match[7];
$tz_code = strtoupper($match[8]);
// Character timezone
if (isset($this->timezone[$tz_code])) {
$timezone = $this->timezone[$tz_code];
}
// Assume everything else to be -0000
else {
$timezone = 0;
}
// Deal with 2 digit year
if ($year < 50) {
$year += 2000;
} else {
$year += 1900;
}
return gmmktime($hour, $minute, $second, $month, $day, $year) - $timezone;
}
return false;
}
/**
* Parse C99's asctime()'s date format
*
* @access protected
* @param string $date
* @return int|false Timestamp
*/
public function date_asctime(string $date)
{
static $pcre;
if (!$pcre) {
$space = '[\x09\x20]+';
$wday_name = $this->day_pcre;
$mon_name = $this->month_pcre;
$day = '([0-9]{1,2})';
$hour = $sec = $min = '([0-9]{2})';
$year = '([0-9]{4})';
$terminator = '\x0A?\x00?';
$pcre = '/^' . $wday_name . $space . $mon_name . $space . $day . $space . $hour . ':' . $min . ':' . $sec . $space . $year . $terminator . '$/i';
}
if (preg_match($pcre, $date, $match)) {
/*
Capturing subpatterns:
1: Day name
2: Month
3: Day
4: Hour
5: Minute
6: Second
7: Year
*/
$month = $this->month[strtolower($match[2])];
return gmmktime((int) $match[4], (int) $match[5], (int) $match[6], $month, (int) $match[3], (int) $match[7]);
}
return false;
}
/**
* Parse dates using strtotime()
*
* @access protected
* @param string $date
* @return int|false Timestamp
*/
public function date_strtotime(string $date)
{
$strtotime = strtotime($date);
if ($strtotime === -1 || $strtotime === false) {
return false;
}
return $strtotime;
}
}
class_alias('SimplePie\Parse\Date', 'SimplePie_Parse_Date');
src/Caption.php 0000644 00000006033 15143517255 0007453 0 ustar 00 ` captions as defined in Media RSS.
*
* Used by {@see \SimplePie\Enclosure::get_caption()} and {@see \SimplePie\Enclosure::get_captions()}
*
* This class can be overloaded with {@see \SimplePie\SimplePie::set_caption_class()}
*/
class Caption
{
/**
* Content type
*
* @var ?string
* @see get_type()
*/
public $type;
/**
* Language
*
* @var ?string
* @see get_language()
*/
public $lang;
/**
* Start time
*
* @var ?string
* @see get_starttime()
*/
public $startTime;
/**
* End time
*
* @var ?string
* @see get_endtime()
*/
public $endTime;
/**
* Caption text
*
* @var ?string
* @see get_text()
*/
public $text;
/**
* Constructor, used to input the data
*
* For documentation on all the parameters, see the corresponding
* properties and their accessors
*/
public function __construct(
?string $type = null,
?string $lang = null,
?string $startTime = null,
?string $endTime = null,
?string $text = null
) {
$this->type = $type;
$this->lang = $lang;
$this->startTime = $startTime;
$this->endTime = $endTime;
$this->text = $text;
}
/**
* String-ified version
*
* @return string
*/
public function __toString()
{
// There is no $this->data here
return md5(serialize($this));
}
/**
* Get the end time
*
* @return string|null Time in the format 'hh:mm:ss.SSS'
*/
public function get_endtime()
{
if ($this->endTime !== null) {
return $this->endTime;
}
return null;
}
/**
* Get the language
*
* @link http://tools.ietf.org/html/rfc3066
* @return string|null Language code as per RFC 3066
*/
public function get_language()
{
if ($this->lang !== null) {
return $this->lang;
}
return null;
}
/**
* Get the start time
*
* @return string|null Time in the format 'hh:mm:ss.SSS'
*/
public function get_starttime()
{
if ($this->startTime !== null) {
return $this->startTime;
}
return null;
}
/**
* Get the text of the caption
*
* @return string|null
*/
public function get_text()
{
if ($this->text !== null) {
return $this->text;
}
return null;
}
/**
* Get the content type (not MIME type)
*
* @return string|null Either 'text' or 'html'
*/
public function get_type()
{
if ($this->type !== null) {
return $this->type;
}
return null;
}
}
class_alias('SimplePie\Caption', 'SimplePie_Caption');
src/RegistryAware.php 0000644 00000000677 15143517255 0010656 0 ustar 00 >
*/
protected $normalization = [
'acap' => [
'port' => 674
],
'dict' => [
'port' => 2628
],
'file' => [
'ihost' => 'localhost'
],
'http' => [
'port' => 80,
'ipath' => '/'
],
'https' => [
'port' => 443,
'ipath' => '/'
],
];
/**
* Return the entire IRI when you try and read the object as a string
*
* @return string
*/
public function __toString()
{
return (string) $this->get_iri();
}
/**
* Overload __set() to provide access via properties
*
* @param string $name Property name
* @param mixed $value Property value
* @return void
*/
public function __set(string $name, $value)
{
$callable = [$this, 'set_' . $name];
if (is_callable($callable)) {
call_user_func($callable, $value);
} elseif (
$name === 'iauthority'
|| $name === 'iuserinfo'
|| $name === 'ihost'
|| $name === 'ipath'
|| $name === 'iquery'
|| $name === 'ifragment'
) {
call_user_func([$this, 'set_' . substr($name, 1)], $value);
}
}
/**
* Overload __get() to provide access via properties
*
* @param string $name Property name
* @return mixed
*/
public function __get(string $name)
{
// isset() returns false for null, we don't want to do that
// Also why we use array_key_exists below instead of isset()
$props = get_object_vars($this);
if (
$name === 'iri' ||
$name === 'uri' ||
$name === 'iauthority' ||
$name === 'authority'
) {
$return = $this->{"get_$name"}();
} elseif (array_key_exists($name, $props)) {
$return = $this->$name;
}
// host -> ihost
elseif (array_key_exists($prop = 'i' . $name, $props)) {
$name = $prop;
$return = $this->$prop;
}
// ischeme -> scheme
elseif (($prop = substr($name, 1)) && array_key_exists($prop, $props)) {
$name = $prop;
$return = $this->$prop;
} else {
trigger_error('Undefined property: ' . get_class($this) . '::' . $name, E_USER_NOTICE);
$return = null;
}
if ($return === null && isset($this->scheme, $this->normalization[$this->scheme][$name])) {
return $this->normalization[$this->scheme][$name];
}
return $return;
}
/**
* Overload __isset() to provide access via properties
*
* @param string $name Property name
* @return bool
*/
public function __isset(string $name)
{
return method_exists($this, 'get_' . $name) || isset($this->$name);
}
/**
* Overload __unset() to provide access via properties
*
* @param string $name Property name
* @return void
*/
public function __unset(string $name)
{
$callable = [$this, 'set_' . $name];
if (is_callable($callable)) {
call_user_func($callable, '');
}
}
/**
* Create a new IRI object, from a specified string
*
* @param string|null $iri
*/
public function __construct(?string $iri = null)
{
$this->set_iri($iri);
}
/**
* Clean up
* @return void
*/
public function __destruct()
{
$this->set_iri(null, true);
$this->set_path(null, true);
$this->set_authority(null, true);
}
/**
* Create a new IRI object by resolving a relative IRI
*
* Returns false if $base is not absolute, otherwise an IRI.
*
* @param IRI|string $base (Absolute) Base IRI
* @param IRI|string $relative Relative IRI
* @return IRI|false
*/
public static function absolutize($base, $relative)
{
if (!($relative instanceof IRI)) {
$relative = new IRI($relative);
}
if (!$relative->is_valid()) {
return false;
} elseif ($relative->scheme !== null) {
return clone $relative;
} else {
if (!($base instanceof IRI)) {
$base = new IRI($base);
}
if ($base->scheme !== null && $base->is_valid()) {
if ($relative->get_iri() !== '') {
if ($relative->iuserinfo !== null || $relative->ihost !== null || $relative->port !== null) {
$target = clone $relative;
$target->scheme = $base->scheme;
} else {
$target = new IRI();
$target->scheme = $base->scheme;
$target->iuserinfo = $base->iuserinfo;
$target->ihost = $base->ihost;
$target->port = $base->port;
if ($relative->ipath !== '') {
if ($relative->ipath[0] === '/') {
$target->ipath = $relative->ipath;
} elseif (($base->iuserinfo !== null || $base->ihost !== null || $base->port !== null) && $base->ipath === '') {
$target->ipath = '/' . $relative->ipath;
} elseif (($last_segment = strrpos($base->ipath, '/')) !== false) {
$target->ipath = substr($base->ipath, 0, $last_segment + 1) . $relative->ipath;
} else {
$target->ipath = $relative->ipath;
}
$target->ipath = $target->remove_dot_segments($target->ipath);
$target->iquery = $relative->iquery;
} else {
$target->ipath = $base->ipath;
if ($relative->iquery !== null) {
$target->iquery = $relative->iquery;
} elseif ($base->iquery !== null) {
$target->iquery = $base->iquery;
}
}
$target->ifragment = $relative->ifragment;
}
} else {
$target = clone $base;
$target->ifragment = null;
}
$target->scheme_normalization();
return $target;
}
return false;
}
}
/**
* Parse an IRI into scheme/authority/path/query/fragment segments
*
* @param string $iri
* @return array{
* scheme: string|null,
* authority: string|null,
* path: string,
* query: string|null,
* fragment: string|null,
* }|false
*/
protected function parse_iri(string $iri)
{
$iri = trim($iri, "\x20\x09\x0A\x0C\x0D");
if (preg_match('/^(?:(?P[^:\/?#]+):)?(:?\/\/(?P[^\/?#]*))?(?P[^?#]*)(?:\?(?P[^#]*))?(?:#(?P.*))?$/', $iri, $match, \PREG_UNMATCHED_AS_NULL)) {
// TODO: Remove once we require PHP ≥ 7.4.
$match['query'] = $match['query'] ?? null;
$match['fragment'] = $match['fragment'] ?? null;
return $match;
}
// This can occur when a paragraph is accidentally parsed as a URI
return false;
}
/**
* Remove dot segments from a path
*
* @param string $input
* @return string
*/
protected function remove_dot_segments(string $input)
{
$output = '';
while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..') {
// A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
if (strpos($input, '../') === 0) {
$input = substr($input, 3);
} elseif (strpos($input, './') === 0) {
$input = substr($input, 2);
}
// B: if the input buffer begins with a prefix of "/./" or "/.", where "." is a complete path segment, then replace that prefix with "/" in the input buffer; otherwise,
elseif (strpos($input, '/./') === 0) {
$input = substr($input, 2);
} elseif ($input === '/.') {
$input = '/';
}
// C: if the input buffer begins with a prefix of "/../" or "/..", where ".." is a complete path segment, then replace that prefix with "/" in the input buffer and remove the last segment and its preceding "/" (if any) from the output buffer; otherwise,
elseif (strpos($input, '/../') === 0) {
$input = substr($input, 3);
$output = substr_replace($output, '', intval(strrpos($output, '/')));
} elseif ($input === '/..') {
$input = '/';
$output = substr_replace($output, '', intval(strrpos($output, '/')));
}
// D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
elseif ($input === '.' || $input === '..') {
$input = '';
}
// E: move the first path segment in the input buffer to the end of the output buffer, including the initial "/" character (if any) and any subsequent characters up to, but not including, the next "/" character or the end of the input buffer
elseif (($pos = strpos($input, '/', 1)) !== false) {
$output .= substr($input, 0, $pos);
$input = substr_replace($input, '', 0, $pos);
} else {
$output .= $input;
$input = '';
}
}
return $output . $input;
}
/**
* Replace invalid character with percent encoding
*
* @param string $string Input string
* @param string $extra_chars Valid characters not in iunreserved or
* iprivate (this is ASCII-only)
* @param bool $iprivate Allow iprivate
* @return string
*/
protected function replace_invalid_with_pct_encoding(string $string, string $extra_chars, bool $iprivate = false)
{
// Normalize as many pct-encoded sections as possible
$string = preg_replace_callback('/(?:%[A-Fa-f0-9]{2})+/', [$this, 'remove_iunreserved_percent_encoded'], $string);
\assert(\is_string($string), "For PHPStan: Should not occur, the regex is valid");
// Replace invalid percent characters
$string = preg_replace('/%(?![A-Fa-f0-9]{2})/', '%25', $string);
\assert(\is_string($string), "For PHPStan: Should not occur, the regex is valid");
// Add unreserved and % to $extra_chars (the latter is safe because all
// pct-encoded sections are now valid).
$extra_chars .= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~%';
// Now replace any bytes that aren't allowed with their pct-encoded versions
$position = 0;
$strlen = strlen($string);
while (($position += strspn($string, $extra_chars, $position)) < $strlen) {
$value = ord($string[$position]);
$character = 0;
// Start position
$start = $position;
// By default we are valid
$valid = true;
// No one byte sequences are valid due to the while.
// Two byte sequence:
if (($value & 0xE0) === 0xC0) {
$character = ($value & 0x1F) << 6;
$length = 2;
$remaining = 1;
}
// Three byte sequence:
elseif (($value & 0xF0) === 0xE0) {
$character = ($value & 0x0F) << 12;
$length = 3;
$remaining = 2;
}
// Four byte sequence:
elseif (($value & 0xF8) === 0xF0) {
$character = ($value & 0x07) << 18;
$length = 4;
$remaining = 3;
}
// Invalid byte:
else {
$valid = false;
$length = 1;
$remaining = 0;
}
if ($remaining) {
if ($position + $length <= $strlen) {
for ($position++; $remaining; $position++) {
$value = ord($string[$position]);
// Check that the byte is valid, then add it to the character:
if (($value & 0xC0) === 0x80) {
$character |= ($value & 0x3F) << (--$remaining * 6);
}
// If it is invalid, count the sequence as invalid and reprocess the current byte:
else {
$valid = false;
$position--;
break;
}
}
} else {
$position = $strlen - 1;
$valid = false;
}
}
// Percent encode anything invalid or not in ucschar
if (
// Invalid sequences
!$valid
// Non-shortest form sequences are invalid
|| $length > 1 && $character <= 0x7F
|| $length > 2 && $character <= 0x7FF
|| $length > 3 && $character <= 0xFFFF
// Outside of range of ucschar codepoints
// Noncharacters
|| ($character & 0xFFFE) === 0xFFFE
|| $character >= 0xFDD0 && $character <= 0xFDEF
|| (
// Everything else not in ucschar
$character > 0xD7FF && $character < 0xF900
|| $character < 0xA0
|| $character > 0xEFFFD
)
&& (
// Everything not in iprivate, if it applies
!$iprivate
|| $character < 0xE000
|| $character > 0x10FFFD
)
) {
// If we were a character, pretend we weren't, but rather an error.
if ($valid) {
$position--;
}
for ($j = $start; $j <= $position; $j++) {
$string = substr_replace($string, sprintf('%%%02X', ord($string[$j])), $j, 1);
$j += 2;
$position += 2;
$strlen += 2;
}
}
}
return $string;
}
/**
* Callback function for preg_replace_callback.
*
* Removes sequences of percent encoded bytes that represent UTF-8
* encoded characters in iunreserved
*
* @param array{string} $match PCRE match, a capture group #0 consisting of a sequence of valid percent-encoded bytes
* @return string Replacement
*/
protected function remove_iunreserved_percent_encoded(array $match)
{
// As we just have valid percent encoded sequences we can just explode
// and ignore the first member of the returned array (an empty string).
$bytes = explode('%', $match[0]);
// Initialize the new string (this is what will be returned) and that
// there are no bytes remaining in the current sequence (unsurprising
// at the first byte!).
$string = '';
$remaining = 0;
// these variables will be initialized in the loop but PHPStan is not able to detect it currently
$start = 0;
$character = 0;
$length = 0;
$valid = true;
// Loop over each and every byte, and set $value to its value
for ($i = 1, $len = count($bytes); $i < $len; $i++) {
$value = hexdec($bytes[$i]);
// If we're the first byte of sequence:
if (!$remaining) {
// Start position
$start = $i;
// By default we are valid
$valid = true;
// One byte sequence:
if ($value <= 0x7F) {
$character = $value;
$length = 1;
}
// Two byte sequence:
elseif (($value & 0xE0) === 0xC0) {
$character = ($value & 0x1F) << 6;
$length = 2;
$remaining = 1;
}
// Three byte sequence:
elseif (($value & 0xF0) === 0xE0) {
$character = ($value & 0x0F) << 12;
$length = 3;
$remaining = 2;
}
// Four byte sequence:
elseif (($value & 0xF8) === 0xF0) {
$character = ($value & 0x07) << 18;
$length = 4;
$remaining = 3;
}
// Invalid byte:
else {
$valid = false;
$remaining = 0;
}
}
// Continuation byte:
else {
// Check that the byte is valid, then add it to the character:
if (($value & 0xC0) === 0x80) {
$remaining--;
$character |= ($value & 0x3F) << ($remaining * 6);
}
// If it is invalid, count the sequence as invalid and reprocess the current byte as the start of a sequence:
else {
$valid = false;
$remaining = 0;
$i--;
}
}
// If we've reached the end of the current byte sequence, append it to Unicode::$data
if (!$remaining) {
// Percent encode anything invalid or not in iunreserved
if (
// Invalid sequences
!$valid
// Non-shortest form sequences are invalid
|| $length > 1 && $character <= 0x7F
|| $length > 2 && $character <= 0x7FF
|| $length > 3 && $character <= 0xFFFF
// Outside of range of iunreserved codepoints
|| $character < 0x2D
|| $character > 0xEFFFD
// Noncharacters
|| ($character & 0xFFFE) === 0xFFFE
|| $character >= 0xFDD0 && $character <= 0xFDEF
// Everything else not in iunreserved (this is all BMP)
|| $character === 0x2F
|| $character > 0x39 && $character < 0x41
|| $character > 0x5A && $character < 0x61
|| $character > 0x7A && $character < 0x7E
|| $character > 0x7E && $character < 0xA0
|| $character > 0xD7FF && $character < 0xF900
) {
for ($j = $start; $j <= $i; $j++) {
$string .= '%' . strtoupper($bytes[$j]);
}
} else {
for ($j = $start; $j <= $i; $j++) {
// Cast for PHPStan, this will always be a number between 0 and 0xFF so hexdec will return int.
$string .= chr((int) hexdec($bytes[$j]));
}
}
}
}
// If we have any bytes left over they are invalid (i.e., we are
// mid-way through a multi-byte sequence)
if ($remaining) {
for ($j = $start; $j < $len; $j++) {
$string .= '%' . strtoupper($bytes[$j]);
}
}
return $string;
}
/**
* @return void
*/
protected function scheme_normalization()
{
if ($this->scheme === null) {
return;
}
if (isset($this->normalization[$this->scheme]['iuserinfo']) && $this->iuserinfo === $this->normalization[$this->scheme]['iuserinfo']) {
$this->iuserinfo = null;
}
if (isset($this->normalization[$this->scheme]['ihost']) && $this->ihost === $this->normalization[$this->scheme]['ihost']) {
$this->ihost = null;
}
if (isset($this->normalization[$this->scheme]['port']) && $this->port === $this->normalization[$this->scheme]['port']) {
$this->port = null;
}
if (isset($this->normalization[$this->scheme]['ipath']) && $this->ipath === $this->normalization[$this->scheme]['ipath']) {
$this->ipath = '';
}
if (isset($this->normalization[$this->scheme]['iquery']) && $this->iquery === $this->normalization[$this->scheme]['iquery']) {
$this->iquery = null;
}
if (isset($this->normalization[$this->scheme]['ifragment']) && $this->ifragment === $this->normalization[$this->scheme]['ifragment']) {
$this->ifragment = null;
}
}
/**
* Check if the object represents a valid IRI. This needs to be done on each
* call as some things change depending on another part of the IRI.
*
* @return bool
*/
public function is_valid()
{
if ($this->ipath === '') {
return true;
}
$isauthority = $this->iuserinfo !== null || $this->ihost !== null ||
$this->port !== null;
if ($isauthority && $this->ipath[0] === '/') {
return true;
}
if (!$isauthority && (substr($this->ipath, 0, 2) === '//')) {
return false;
}
// Relative urls cannot have a colon in the first path segment (and the
// slashes themselves are not included so skip the first character).
if (!$this->scheme && !$isauthority &&
strpos($this->ipath, ':') !== false &&
strpos($this->ipath, '/', 1) !== false &&
strpos($this->ipath, ':') < strpos($this->ipath, '/', 1)) {
return false;
}
return true;
}
/**
* Set the entire IRI. Returns true on success, false on failure (if there
* are any invalid characters).
*
* @param string|null $iri
* @return bool
*/
public function set_iri(?string $iri, bool $clear_cache = false)
{
static $cache;
if ($clear_cache) {
$cache = null;
return false;
}
if (!$cache) {
$cache = [];
}
if ($iri === null) {
return true;
} elseif (isset($cache[$iri])) {
[
$this->scheme,
$this->iuserinfo,
$this->ihost,
$this->port,
$this->ipath,
$this->iquery,
$this->ifragment,
$return
] = $cache[$iri];
return $return;
}
$parsed = $this->parse_iri((string) $iri);
if (!$parsed) {
return false;
}
$return = $this->set_scheme($parsed['scheme'])
&& $this->set_authority($parsed['authority'])
&& $this->set_path($parsed['path'])
&& $this->set_query($parsed['query'])
&& $this->set_fragment($parsed['fragment']);
$cache[$iri] = [
$this->scheme,
$this->iuserinfo,
$this->ihost,
$this->port,
$this->ipath,
$this->iquery,
$this->ifragment,
$return
];
return $return;
}
/**
* Set the scheme. Returns true on success, false on failure (if there are
* any invalid characters).
*
* @param string|null $scheme
* @return bool
*/
public function set_scheme(?string $scheme)
{
if ($scheme === null) {
$this->scheme = null;
} elseif (!preg_match('/^[A-Za-z][0-9A-Za-z+\-.]*$/', $scheme)) {
$this->scheme = null;
return false;
} else {
$this->scheme = strtolower($scheme);
}
return true;
}
/**
* Set the authority. Returns true on success, false on failure (if there are
* any invalid characters).
*
* @param string|null $authority
* @return bool
*/
public function set_authority(?string $authority, bool $clear_cache = false)
{
static $cache;
if ($clear_cache) {
$cache = null;
return false;
}
if (!$cache) {
$cache = [];
}
if ($authority === null) {
$this->iuserinfo = null;
$this->ihost = null;
$this->port = null;
return true;
} elseif (isset($cache[$authority])) {
[
$this->iuserinfo,
$this->ihost,
$this->port,
$return
] = $cache[$authority];
return $return;
}
$remaining = $authority;
if (($iuserinfo_end = strrpos($remaining, '@')) !== false) {
// Cast for PHPStan on PHP < 8.0. It does not detect that
// the range is not flipped so substr cannot return false.
$iuserinfo = (string) substr($remaining, 0, $iuserinfo_end);
$remaining = substr($remaining, $iuserinfo_end + 1);
} else {
$iuserinfo = null;
}
if (($port_start = strpos($remaining, ':', intval(strpos($remaining, ']')))) !== false) {
$port = substr($remaining, $port_start + 1);
if ($port === false) {
$port = null;
}
$remaining = substr($remaining, 0, $port_start);
} else {
$port = null;
}
$return = $this->set_userinfo($iuserinfo) &&
$this->set_host($remaining) &&
$this->set_port($port);
$cache[$authority] = [
$this->iuserinfo,
$this->ihost,
$this->port,
$return
];
return $return;
}
/**
* Set the iuserinfo.
*
* @param string|null $iuserinfo
* @return bool
*/
public function set_userinfo(?string $iuserinfo)
{
if ($iuserinfo === null) {
$this->iuserinfo = null;
} else {
$this->iuserinfo = $this->replace_invalid_with_pct_encoding($iuserinfo, '!$&\'()*+,;=:');
$this->scheme_normalization();
}
return true;
}
/**
* Set the ihost. Returns true on success, false on failure (if there are
* any invalid characters).
*
* @param string|null $ihost
* @return bool
*/
public function set_host(?string $ihost)
{
if ($ihost === null) {
$this->ihost = null;
return true;
} elseif (substr($ihost, 0, 1) === '[' && substr($ihost, -1) === ']') {
if (\SimplePie\Net\IPv6::check_ipv6(substr($ihost, 1, -1))) {
$this->ihost = '[' . \SimplePie\Net\IPv6::compress(substr($ihost, 1, -1)) . ']';
} else {
$this->ihost = null;
return false;
}
} else {
$ihost = $this->replace_invalid_with_pct_encoding($ihost, '!$&\'()*+,;=');
// Lowercase, but ignore pct-encoded sections (as they should
// remain uppercase). This must be done after the previous step
// as that can add unescaped characters.
$position = 0;
$strlen = strlen($ihost);
while (($position += strcspn($ihost, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ%', $position)) < $strlen) {
if ($ihost[$position] === '%') {
$position += 3;
} else {
$ihost[$position] = strtolower($ihost[$position]);
$position++;
}
}
$this->ihost = $ihost;
}
$this->scheme_normalization();
return true;
}
/**
* Set the port. Returns true on success, false on failure (if there are
* any invalid characters).
*
* @param string|int|null $port
* @return bool
*/
public function set_port($port)
{
if ($port === null) {
$this->port = null;
return true;
} elseif (strspn((string) $port, '0123456789') === strlen((string) $port)) {
$this->port = (int) $port;
$this->scheme_normalization();
return true;
}
$this->port = null;
return false;
}
/**
* Set the ipath.
*
* @param string|null $ipath
* @return bool
*/
public function set_path(?string $ipath, bool $clear_cache = false)
{
static $cache;
if ($clear_cache) {
$cache = null;
return false;
}
if (!$cache) {
$cache = [];
}
$ipath = (string) $ipath;
if (isset($cache[$ipath])) {
$this->ipath = $cache[$ipath][(int) ($this->scheme !== null)];
} else {
$valid = $this->replace_invalid_with_pct_encoding($ipath, '!$&\'()*+,;=@:/');
$removed = $this->remove_dot_segments($valid);
$cache[$ipath] = [$valid, $removed];
$this->ipath = ($this->scheme !== null) ? $removed : $valid;
}
$this->scheme_normalization();
return true;
}
/**
* Set the iquery.
*
* @param string|null $iquery
* @return bool
*/
public function set_query(?string $iquery)
{
if ($iquery === null) {
$this->iquery = null;
} else {
$this->iquery = $this->replace_invalid_with_pct_encoding($iquery, '!$&\'()*+,;=:@/?', true);
$this->scheme_normalization();
}
return true;
}
/**
* Set the ifragment.
*
* @param string|null $ifragment
* @return bool
*/
public function set_fragment(?string $ifragment)
{
if ($ifragment === null) {
$this->ifragment = null;
} else {
$this->ifragment = $this->replace_invalid_with_pct_encoding($ifragment, '!$&\'()*+,;=:@/?');
$this->scheme_normalization();
}
return true;
}
/**
* Convert an IRI to a URI (or parts thereof)
*
* @param string $string
* @return string
*/
public function to_uri(string $string)
{
static $non_ascii;
if (!$non_ascii) {
$non_ascii = implode('', range("\x80", "\xFF"));
}
$position = 0;
$strlen = strlen($string);
while (($position += strcspn($string, $non_ascii, $position)) < $strlen) {
$string = substr_replace($string, sprintf('%%%02X', ord($string[$position])), $position, 1);
$position += 3;
$strlen += 2;
}
return $string;
}
/**
* Get the complete IRI
*
* @return string|false
*/
public function get_iri()
{
if (!$this->is_valid()) {
return false;
}
$iri = '';
if ($this->scheme !== null) {
$iri .= $this->scheme . ':';
}
if (($iauthority = $this->get_iauthority()) !== null) {
$iri .= '//' . $iauthority;
}
if ($this->ipath !== '') {
$iri .= $this->ipath;
} elseif (!empty($this->normalization[$this->scheme]['ipath']) && $iauthority !== null && $iauthority !== '') {
$iri .= $this->normalization[$this->scheme]['ipath'];
}
if ($this->iquery !== null) {
$iri .= '?' . $this->iquery;
}
if ($this->ifragment !== null) {
$iri .= '#' . $this->ifragment;
}
return $iri;
}
/**
* Get the complete URI
*
* @return string
*/
public function get_uri()
{
return $this->to_uri((string) $this->get_iri());
}
/**
* Get the complete iauthority
*
* @return ?string
*/
protected function get_iauthority()
{
if ($this->iuserinfo !== null || $this->ihost !== null || $this->port !== null) {
$iauthority = '';
if ($this->iuserinfo !== null) {
$iauthority .= $this->iuserinfo . '@';
}
if ($this->ihost !== null) {
$iauthority .= $this->ihost;
}
if ($this->port !== null && $this->port !== 0) {
$iauthority .= ':' . $this->port;
}
return $iauthority;
}
return null;
}
/**
* Get the complete authority
*
* @return ?string
*/
protected function get_authority()
{
$iauthority = $this->get_iauthority();
if (is_string($iauthority)) {
return $this->to_uri($iauthority);
}
return $iauthority;
}
}
class_alias('SimplePie\IRI', 'SimplePie_IRI');
src/Sanitize.php 0000644 00000073221 15143517255 0007647 0 ustar 00 > */
public $add_attributes = ['audio' => ['preload' => 'none'], 'iframe' => ['sandbox' => 'allow-scripts allow-same-origin'], 'video' => ['preload' => 'none']];
/** @var bool */
public $strip_comments = false;
/** @var string */
public $output_encoding = 'UTF-8';
/** @var bool */
public $enable_cache = true;
/** @var string */
public $cache_location = './cache';
/** @var string&(callable(string): string) */
public $cache_name_function = 'md5';
/**
* @var NameFilter
*/
private $cache_namefilter;
/** @var int */
public $timeout = 10;
/** @var string */
public $useragent = '';
/** @var bool */
public $force_fsockopen = false;
/** @var array */
public $replace_url_attributes = [];
/**
* @var array Custom curl options
* @see SimplePie::set_curl_options()
*/
private $curl_options = [];
/** @var Registry */
public $registry;
/**
* @var DataCache|null
*/
private $cache = null;
/**
* @var int Cache duration (in seconds)
*/
private $cache_duration = 3600;
/**
* List of domains for which to force HTTPS.
* @see \SimplePie\Sanitize::set_https_domains()
* Array is a tree split at DNS levels. Example:
* array('biz' => true, 'com' => array('example' => true), 'net' => array('example' => array('www' => true)))
* @var true|array>>>>>
*/
public $https_domains = [];
/**
* @var Client|null
*/
private $http_client = null;
public function __construct()
{
// Set defaults
$this->set_url_replacements(null);
}
/**
* @return void
*/
public function remove_div(bool $enable = true)
{
$this->remove_div = (bool) $enable;
}
/**
* @param string|false $page
* @return void
*/
public function set_image_handler($page = false)
{
if ($page) {
$this->image_handler = (string) $page;
} else {
$this->image_handler = '';
}
}
/**
* @return void
*/
public function set_registry(\SimplePie\Registry $registry)
{
$this->registry = $registry;
}
/**
* @param (string&(callable(string): string))|NameFilter $cache_name_function
* @param class-string $cache_class
* @return void
*/
public function pass_cache_data(bool $enable_cache = true, string $cache_location = './cache', $cache_name_function = 'md5', string $cache_class = Cache::class, ?DataCache $cache = null)
{
$this->enable_cache = $enable_cache;
if ($cache_location) {
$this->cache_location = $cache_location;
}
// @phpstan-ignore-next-line Enforce PHPDoc type.
if (!is_string($cache_name_function) && !$cache_name_function instanceof NameFilter) {
throw new InvalidArgumentException(sprintf(
'%s(): Argument #3 ($cache_name_function) must be of type %s',
__METHOD__,
NameFilter::class
), 1);
}
// BC: $cache_name_function could be a callable as string
if (is_string($cache_name_function)) {
// trigger_error(sprintf('Providing $cache_name_function as string in "%s()" is deprecated since SimplePie 1.8.0, provide as "%s" instead.', __METHOD__, NameFilter::class), \E_USER_DEPRECATED);
$this->cache_name_function = $cache_name_function;
$cache_name_function = new CallableNameFilter($cache_name_function);
}
$this->cache_namefilter = $cache_name_function;
if ($cache !== null) {
$this->cache = $cache;
}
}
/**
* Set a PSR-18 client and PSR-17 factories
*
* Allows you to use your own HTTP client implementations.
*/
final public function set_http_client(
ClientInterface $http_client,
RequestFactoryInterface $request_factory,
UriFactoryInterface $uri_factory
): void {
$this->http_client = new Psr18Client($http_client, $request_factory, $uri_factory);
}
/**
* @deprecated since SimplePie 1.9.0, use \SimplePie\Sanitize::set_http_client() instead.
* @param class-string $file_class
* @param array $curl_options
* @return void
*/
public function pass_file_data(string $file_class = File::class, int $timeout = 10, string $useragent = '', bool $force_fsockopen = false, array $curl_options = [])
{
// trigger_error(sprintf('SimplePie\Sanitize::pass_file_data() is deprecated since SimplePie 1.9.0, please use "SimplePie\Sanitize::set_http_client()" instead.'), \E_USER_DEPRECATED);
if ($timeout) {
$this->timeout = $timeout;
}
if ($useragent) {
$this->useragent = $useragent;
}
if ($force_fsockopen) {
$this->force_fsockopen = $force_fsockopen;
}
$this->curl_options = $curl_options;
// Invalidate the registered client.
$this->http_client = null;
}
/**
* @param string[]|string|false $tags Set a list of tags to strip, or set empty string to use default tags, or false to strip nothing.
* @return void
*/
public function strip_htmltags($tags = ['base', 'blink', 'body', 'doctype', 'embed', 'font', 'form', 'frame', 'frameset', 'html', 'iframe', 'input', 'marquee', 'meta', 'noscript', 'object', 'param', 'script', 'style'])
{
if ($tags) {
if (is_array($tags)) {
$this->strip_htmltags = $tags;
} else {
$this->strip_htmltags = explode(',', $tags);
}
} else {
$this->strip_htmltags = [];
}
}
/**
* @return void
*/
public function encode_instead_of_strip(bool $encode = false)
{
$this->encode_instead_of_strip = $encode;
}
/**
* @param string[]|string $attribs
* @return void
*/
public function rename_attributes($attribs = [])
{
if ($attribs) {
if (is_array($attribs)) {
$this->rename_attributes = $attribs;
} else {
$this->rename_attributes = explode(',', $attribs);
}
} else {
$this->rename_attributes = [];
}
}
/**
* @param string[]|string $attribs
* @return void
*/
public function strip_attributes($attribs = ['bgsound', 'expr', 'id', 'style', 'onclick', 'onerror', 'onfinish', 'onmouseover', 'onmouseout', 'onfocus', 'onblur', 'lowsrc', 'dynsrc'])
{
if ($attribs) {
if (is_array($attribs)) {
$this->strip_attributes = $attribs;
} else {
$this->strip_attributes = explode(',', $attribs);
}
} else {
$this->strip_attributes = [];
}
}
/**
* @param array> $attribs
* @return void
*/
public function add_attributes(array $attribs = ['audio' => ['preload' => 'none'], 'iframe' => ['sandbox' => 'allow-scripts allow-same-origin'], 'video' => ['preload' => 'none']])
{
$this->add_attributes = $attribs;
}
/**
* @return void
*/
public function strip_comments(bool $strip = false)
{
$this->strip_comments = $strip;
}
/**
* @return void
*/
public function set_output_encoding(string $encoding = 'UTF-8')
{
$this->output_encoding = $encoding;
}
/**
* Set element/attribute key/value pairs of HTML attributes
* containing URLs that need to be resolved relative to the feed
*
* Defaults to |a|@href, |area|@href, |audio|@src, |blockquote|@cite,
* |del|@cite, |form|@action, |img|@longdesc, |img|@src, |input|@src,
* |ins|@cite, |q|@cite, |source|@src, |video|@src
*
* @since 1.0
* @param array|null $element_attribute Element/attribute key/value pairs, null for default
* @return void
*/
public function set_url_replacements(?array $element_attribute = null)
{
if ($element_attribute === null) {
$element_attribute = [
'a' => 'href',
'area' => 'href',
'audio' => 'src',
'blockquote' => 'cite',
'del' => 'cite',
'form' => 'action',
'img' => [
'longdesc',
'src'
],
'input' => 'src',
'ins' => 'cite',
'q' => 'cite',
'source' => 'src',
'video' => [
'poster',
'src'
]
];
}
$this->replace_url_attributes = $element_attribute;
}
/**
* Set the list of domains for which to force HTTPS.
* @see \SimplePie\Misc::https_url()
* Example array('biz', 'example.com', 'example.org', 'www.example.net');
*
* @param string[] $domains list of domain names ['biz', 'example.com', 'example.org', 'www.example.net']
*
* @return void
*/
public function set_https_domains(array $domains)
{
$this->https_domains = [];
foreach ($domains as $domain) {
$domain = trim($domain, ". \t\n\r\0\x0B");
$segments = array_reverse(explode('.', $domain));
/** @var true|array>>>>> */ // Needed for PHPStan.
$node = &$this->https_domains;
foreach ($segments as $segment) {//Build a tree
if ($node === true) {
break;
}
if (!isset($node[$segment])) {
$node[$segment] = [];
}
$node = &$node[$segment];
}
$node = true;
}
}
/**
* Check if the domain is in the list of forced HTTPS.
*
* @return bool
*/
protected function is_https_domain(string $domain)
{
$domain = trim($domain, '. ');
$segments = array_reverse(explode('.', $domain));
$node = &$this->https_domains;
foreach ($segments as $segment) {//Explore the tree
if (isset($node[$segment])) {
$node = &$node[$segment];
} else {
break;
}
}
return $node === true;
}
/**
* Force HTTPS for selected Web sites.
*
* @return string
*/
public function https_url(string $url)
{
return (
strtolower(substr($url, 0, 7)) === 'http://'
&& ($parsed = parse_url($url, PHP_URL_HOST)) !== false // Malformed URL
&& $parsed !== null // Missing host
&& $this->is_https_domain($parsed) // Should be forced?
) ? substr_replace($url, 's', 4, 0) // Add the 's' to HTTPS
: $url;
}
/**
* @param int-mask-of $type
* @param string $base
* @return string Sanitized data; false if output encoding is changed to something other than UTF-8 and conversion fails
*/
public function sanitize(string $data, int $type, string $base = '')
{
$data = trim($data);
if ($data !== '' || $type & \SimplePie\SimplePie::CONSTRUCT_IRI) {
if ($type & \SimplePie\SimplePie::CONSTRUCT_MAYBE_HTML) {
if (preg_match('/(&(#(x[0-9a-fA-F]+|[0-9]+)|[a-zA-Z0-9]+)|<\/[A-Za-z][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E]*' . \SimplePie\SimplePie::PCRE_HTML_ATTRIBUTE . '>)/', $data)) {
$type |= \SimplePie\SimplePie::CONSTRUCT_HTML;
} else {
$type |= \SimplePie\SimplePie::CONSTRUCT_TEXT;
}
}
if ($type & \SimplePie\SimplePie::CONSTRUCT_BASE64) {
$data = base64_decode($data);
}
if ($type & (\SimplePie\SimplePie::CONSTRUCT_HTML | \SimplePie\SimplePie::CONSTRUCT_XHTML)) {
if (!class_exists('DOMDocument')) {
throw new \SimplePie\Exception('DOMDocument not found, unable to use sanitizer');
}
$document = new \DOMDocument();
$document->encoding = 'UTF-8';
// PHPStan seems to have trouble resolving int-mask because bitwise
// operators are used when operators are used when passing this parameter.
// https://github.com/phpstan/phpstan/issues/9384
/** @var int-mask-of $type */
$data = $this->preprocess($data, $type);
set_error_handler([Misc::class, 'silence_errors']);
$document->loadHTML($data);
restore_error_handler();
$xpath = new \DOMXPath($document);
// Strip comments
if ($this->strip_comments) {
/** @var \DOMNodeList<\DOMComment> */
$comments = $xpath->query('//comment()');
foreach ($comments as $comment) {
$parentNode = $comment->parentNode;
assert($parentNode !== null, 'For PHPStan, comment must have a parent');
$parentNode->removeChild($comment);
}
}
// Strip out HTML tags and attributes that might cause various security problems.
// Based on recommendations by Mark Pilgrim at:
// https://web.archive.org/web/20110902041826/http://diveintomark.org:80/archives/2003/06/12/how_to_consume_rss_safely
if ($this->strip_htmltags) {
foreach ($this->strip_htmltags as $tag) {
$this->strip_tag($tag, $document, $xpath, $type);
}
}
if ($this->rename_attributes) {
foreach ($this->rename_attributes as $attrib) {
$this->rename_attr($attrib, $xpath);
}
}
if ($this->strip_attributes) {
foreach ($this->strip_attributes as $attrib) {
$this->strip_attr($attrib, $xpath);
}
}
if ($this->add_attributes) {
foreach ($this->add_attributes as $tag => $valuePairs) {
$this->add_attr($tag, $valuePairs, $document);
}
}
// Replace relative URLs
$this->base = $base;
foreach ($this->replace_url_attributes as $element => $attributes) {
$this->replace_urls($document, $element, $attributes);
}
// If image handling (caching, etc.) is enabled, cache and rewrite all the image tags.
if ($this->image_handler !== '' && $this->enable_cache) {
$images = $document->getElementsByTagName('img');
foreach ($images as $img) {
if ($img->hasAttribute('src')) {
$image_url = $this->cache_namefilter->filter($img->getAttribute('src'));
$cache = $this->get_cache($image_url);
if ($cache->get_data($image_url, false)) {
$img->setAttribute('src', $this->image_handler . $image_url);
} else {
try {
$file = $this->get_http_client()->request(
Client::METHOD_GET,
$img->getAttribute('src'),
['X-FORWARDED-FOR' => $_SERVER['REMOTE_ADDR']]
);
} catch (ClientException $th) {
continue;
}
if ((!Misc::is_remote_uri($file->get_final_requested_uri()) || ($file->get_status_code() === 200 || $file->get_status_code() > 206 && $file->get_status_code() < 300))) {
if ($cache->set_data($image_url, ['headers' => $file->get_headers(), 'body' => $file->get_body_content()], $this->cache_duration)) {
$img->setAttribute('src', $this->image_handler . $image_url);
} else {
trigger_error("$this->cache_location is not writable. Make sure you've set the correct relative or absolute path, and that the location is server-writable.", E_USER_WARNING);
}
}
}
}
}
}
// Get content node
$div = null;
if (($item = $document->getElementsByTagName('body')->item(0)) !== null) {
$div = $item->firstChild;
}
// Finally, convert to a HTML string
$data = trim((string) $document->saveHTML($div));
if ($this->remove_div) {
$data = preg_replace('/^
/', '', $data);
// Cast for PHPStan, it is unable to validate a non-literal regex above.
$data = preg_replace('/<\/div>$/', '', (string) $data);
} else {
$data = preg_replace('/^
/', '
', $data);
}
// Cast for PHPStan, it is unable to validate a non-literal regex above.
$data = str_replace('', '', (string) $data);
}
if ($type & \SimplePie\SimplePie::CONSTRUCT_IRI) {
$absolute = $this->registry->call(Misc::class, 'absolutize_url', [$data, $base]);
if ($absolute !== false) {
$data = $absolute;
}
}
if ($type & (\SimplePie\SimplePie::CONSTRUCT_TEXT | \SimplePie\SimplePie::CONSTRUCT_IRI)) {
$data = htmlspecialchars($data, ENT_COMPAT, 'UTF-8');
}
if ($this->output_encoding !== 'UTF-8') {
// This really returns string|false but changing encoding is uncommon and we are going to deprecate it, so let’s just lie to PHPStan in the interest of cleaner annotations.
/** @var string */
$data = $this->registry->call(Misc::class, 'change_encoding', [$data, 'UTF-8', $this->output_encoding]);
}
}
return $data;
}
/**
* @param int-mask-of $type
* @return string
*/
protected function preprocess(string $html, int $type)
{
$ret = '';
$html = preg_replace('%?(?:html|body)[^>]*?'.'>%is', '', $html);
if ($type & ~\SimplePie\SimplePie::CONSTRUCT_XHTML) {
// Atom XHTML constructs are wrapped with a div by default
// Note: No protection if $html contains a stray
!
$html = '
' . $html . '
';
$ret .= '';
$content_type = 'text/html';
} else {
$ret .= '';
$content_type = 'application/xhtml+xml';
}
$ret .= '';
$ret .= '';
$ret .= '' . $html . '';
return $ret;
}
/**
* @param array|string $attributes
* @return void
*/
public function replace_urls(DOMDocument $document, string $tag, $attributes)
{
if (!is_array($attributes)) {
$attributes = [$attributes];
}
if (!is_array($this->strip_htmltags) || !in_array($tag, $this->strip_htmltags)) {
$elements = $document->getElementsByTagName($tag);
foreach ($elements as $element) {
foreach ($attributes as $attribute) {
if ($element->hasAttribute($attribute)) {
$value = $this->registry->call(Misc::class, 'absolutize_url', [$element->getAttribute($attribute), $this->base]);
if ($value !== false) {
$value = $this->https_url($value);
$element->setAttribute($attribute, $value);
}
}
}
}
}
}
/**
* @param array $match
* @return string
*/
public function do_strip_htmltags(array $match)
{
if ($this->encode_instead_of_strip) {
if (isset($match[4]) && !in_array(strtolower($match[1]), ['script', 'style'])) {
$match[1] = htmlspecialchars($match[1], ENT_COMPAT, 'UTF-8');
$match[2] = htmlspecialchars($match[2], ENT_COMPAT, 'UTF-8');
return "<$match[1]$match[2]>$match[3]</$match[1]>";
} else {
return htmlspecialchars($match[0], ENT_COMPAT, 'UTF-8');
}
} elseif (isset($match[4]) && !in_array(strtolower($match[1]), ['script', 'style'])) {
return $match[4];
} else {
return '';
}
}
/**
* @param int-mask-of $type
* @return void
*/
protected function strip_tag(string $tag, DOMDocument $document, DOMXPath $xpath, int $type)
{
$elements = $xpath->query('body//' . $tag);
if ($elements === false) {
throw new \SimplePie\Exception(sprintf(
'%s(): Possibly malformed expression, check argument #1 ($tag)',
__METHOD__
), 1);
}
if ($this->encode_instead_of_strip) {
foreach ($elements as $element) {
$fragment = $document->createDocumentFragment();
// For elements which aren't script or style, include the tag itself
if (!in_array($tag, ['script', 'style'])) {
$text = '<' . $tag;
if ($element->attributes !== null) {
$attrs = [];
foreach ($element->attributes as $name => $attr) {
$value = $attr->value;
// In XHTML, empty values should never exist, so we repeat the value
if (empty($value) && ($type & \SimplePie\SimplePie::CONSTRUCT_XHTML)) {
$value = $name;
}
// For HTML, empty is fine
elseif (empty($value) && ($type & \SimplePie\SimplePie::CONSTRUCT_HTML)) {
$attrs[] = $name;
continue;
}
// Standard attribute text
$attrs[] = $name . '="' . $attr->value . '"';
}
$text .= ' ' . implode(' ', $attrs);
}
$text .= '>';
$fragment->appendChild(new \DOMText($text));
}
$number = $element->childNodes->length;
for ($i = $number; $i > 0; $i--) {
if (($child = $element->childNodes->item(0)) !== null) {
$fragment->appendChild($child);
}
}
if (!in_array($tag, ['script', 'style'])) {
$fragment->appendChild(new \DOMText('' . $tag . '>'));
}
if (($parentNode = $element->parentNode) !== null) {
$parentNode->replaceChild($fragment, $element);
}
}
return;
} elseif (in_array($tag, ['script', 'style'])) {
foreach ($elements as $element) {
if (($parentNode = $element->parentNode) !== null) {
$parentNode->removeChild($element);
}
}
return;
} else {
foreach ($elements as $element) {
$fragment = $document->createDocumentFragment();
$number = $element->childNodes->length;
for ($i = $number; $i > 0; $i--) {
if (($child = $element->childNodes->item(0)) !== null) {
$fragment->appendChild($child);
}
}
if (($parentNode = $element->parentNode) !== null) {
$parentNode->replaceChild($fragment, $element);
}
}
}
}
/**
* @return void
*/
protected function strip_attr(string $attrib, DOMXPath $xpath)
{
$elements = $xpath->query('//*[@' . $attrib . ']');
if ($elements === false) {
throw new \SimplePie\Exception(sprintf(
'%s(): Possibly malformed expression, check argument #1 ($attrib)',
__METHOD__
), 1);
}
/** @var \DOMElement $element */
foreach ($elements as $element) {
$element->removeAttribute($attrib);
}
}
/**
* @return void
*/
protected function rename_attr(string $attrib, DOMXPath $xpath)
{
$elements = $xpath->query('//*[@' . $attrib . ']');
if ($elements === false) {
throw new \SimplePie\Exception(sprintf(
'%s(): Possibly malformed expression, check argument #1 ($attrib)',
__METHOD__
), 1);
}
/** @var \DOMElement $element */
foreach ($elements as $element) {
$element->setAttribute('data-sanitized-' . $attrib, $element->getAttribute($attrib));
$element->removeAttribute($attrib);
}
}
/**
* @param array $valuePairs
* @return void
*/
protected function add_attr(string $tag, array $valuePairs, DOMDocument $document)
{
$elements = $document->getElementsByTagName($tag);
/** @var \DOMElement $element */
foreach ($elements as $element) {
foreach ($valuePairs as $attrib => $value) {
$element->setAttribute($attrib, $value);
}
}
}
/**
* Get a DataCache
*
* @param string $image_url Only needed for BC, can be removed in SimplePie 2.0.0
*
* @return DataCache
*/
private function get_cache(string $image_url = ''): DataCache
{
if ($this->cache === null) {
// @trigger_error(sprintf('Not providing as PSR-16 cache implementation is deprecated since SimplePie 1.8.0, please use "SimplePie\SimplePie::set_cache()".'), \E_USER_DEPRECATED);
$cache = $this->registry->call(Cache::class, 'get_handler', [
$this->cache_location,
$image_url,
Base::TYPE_IMAGE
]);
return new BaseDataCache($cache);
}
return $this->cache;
}
/**
* Get a HTTP client
*/
private function get_http_client(): Client
{
if ($this->http_client === null) {
$this->http_client = new FileClient(
$this->registry,
[
'timeout' => $this->timeout,
'redirects' => 5,
'useragent' => $this->useragent,
'force_fsockopen' => $this->force_fsockopen,
'curl_options' => $this->curl_options,
]
);
}
return $this->http_client;
}
}
class_alias('SimplePie\Sanitize', 'SimplePie_Sanitize');
src/Registry.php 0000644 00000017330 15143517255 0007670 0 ustar 00
*/
protected $default = [
Cache::class => Cache::class,
Locator::class => Locator::class,
Parser::class => Parser::class,
File::class => File::class,
Sanitize::class => Sanitize::class,
Item::class => Item::class,
Author::class => Author::class,
Category::class => Category::class,
Enclosure::class => Enclosure::class,
Caption::class => Caption::class,
Copyright::class => Copyright::class,
Credit::class => Credit::class,
Rating::class => Rating::class,
Restriction::class => Restriction::class,
Sniffer::class => Sniffer::class,
Source::class => Source::class,
Misc::class => Misc::class,
DeclarationParser::class => DeclarationParser::class,
Date::class => Date::class,
];
/**
* Class mapping
*
* @see register()
* @var array
*/
protected $classes = [];
/**
* Legacy classes
*
* @see register()
* @var array
*/
protected $legacy = [];
/**
* Legacy types
*
* @see register()
* @var array
*/
private $legacyTypes = [
'Cache' => Cache::class,
'Locator' => Locator::class,
'Parser' => Parser::class,
'File' => File::class,
'Sanitize' => Sanitize::class,
'Item' => Item::class,
'Author' => Author::class,
'Category' => Category::class,
'Enclosure' => Enclosure::class,
'Caption' => Caption::class,
'Copyright' => Copyright::class,
'Credit' => Credit::class,
'Rating' => Rating::class,
'Restriction' => Restriction::class,
'Content_Type_Sniffer' => Sniffer::class,
'Source' => Source::class,
'Misc' => Misc::class,
'XML_Declaration_Parser' => DeclarationParser::class,
'Parse_Date' => Date::class,
];
/**
* Constructor
*
* No-op
*/
public function __construct()
{
}
/**
* Register a class
*
* @param string $type See {@see $default} for names
* @param class-string $class Class name, must subclass the corresponding default
* @param bool $legacy Whether to enable legacy support for this class
* @return bool Successfulness
*/
public function register(string $type, $class, bool $legacy = false)
{
if (array_key_exists($type, $this->legacyTypes)) {
// trigger_error(sprintf('"%s"(): Using argument #1 ($type) with value "%s" is deprecated since SimplePie 1.8.0, use class-string "%s" instead.', __METHOD__, $type, $this->legacyTypes[$type]), \E_USER_DEPRECATED);
$type = $this->legacyTypes[$type];
}
if (!array_key_exists($type, $this->default)) {
return false;
}
if (!class_exists($class)) {
return false;
}
/** @var string */
$base_class = $this->default[$type];
if (!is_subclass_of($class, $base_class)) {
return false;
}
$this->classes[$type] = $class;
if ($legacy) {
$this->legacy[] = $class;
}
return true;
}
/**
* Get the class registered for a type
*
* Where possible, use {@see create()} or {@see call()} instead
*
* @template T
* @param class-string $type
* @return class-string|null
*/
public function get_class($type)
{
if (array_key_exists($type, $this->legacyTypes)) {
// trigger_error(sprintf('"%s"(): Using argument #1 ($type) with value "%s" is deprecated since SimplePie 1.8.0, use class-string "%s" instead.', __METHOD__, $type, $this->legacyTypes[$type]), \E_USER_DEPRECATED);
$type = $this->legacyTypes[$type];
}
if (!array_key_exists($type, $this->default)) {
return null;
}
// For PHPStan: values in $default should be subtypes of keys.
/** @var class-string */
$class = $this->default[$type];
if (array_key_exists($type, $this->classes)) {
// For PHPStan: values in $classes should be subtypes of keys.
/** @var class-string */
$class = $this->classes[$type];
}
return $class;
}
/**
* Create a new instance of a given type
*
* @template T class-string $type
* @param class-string $type
* @param array $parameters Parameters to pass to the constructor
* @return T Instance of class
*/
public function &create($type, array $parameters = [])
{
$class = $this->get_class($type);
if ($class === null) {
throw new InvalidArgumentException(sprintf(
'%s(): Argument #1 ($type) "%s" not found in class list.',
__METHOD__,
$type
), 1);
}
if (!method_exists($class, '__construct')) {
$instance = new $class();
} else {
$reflector = new \ReflectionClass($class);
// For PHPStan: $class is T.
/** @var T */
$instance = $reflector->newInstanceArgs($parameters);
}
if ($instance instanceof RegistryAware) {
$instance->set_registry($this);
} elseif (method_exists($instance, 'set_registry')) {
trigger_error(sprintf('Using the method "set_registry()" without implementing "%s" is deprecated since SimplePie 1.8.0, implement "%s" in "%s".', RegistryAware::class, RegistryAware::class, $class), \E_USER_DEPRECATED);
$instance->set_registry($this);
}
return $instance;
}
/**
* Call a static method for a type
*
* @param class-string $type
* @param string $method
* @param array $parameters
* @return mixed
*/
public function &call($type, string $method, array $parameters = [])
{
$class = $this->get_class($type);
if ($class === null) {
throw new InvalidArgumentException(sprintf(
'%s(): Argument #1 ($type) "%s" not found in class list.',
__METHOD__,
$type
), 1);
}
if (in_array($class, $this->legacy)) {
switch ($type) {
case Cache::class:
// For backwards compatibility with old non-static
// Cache::create() methods in PHP < 8.0.
// No longer supported as of PHP 8.0.
if ($method === 'get_handler') {
// Fixing this PHPStan error breaks CacheTest::testDirectOverrideLegacy()
/** @phpstan-ignore argument.type */
$result = @call_user_func_array([$class, 'create'], $parameters);
return $result;
}
break;
}
}
$callable = [$class, $method];
assert(is_callable($callable), 'For PHPstan');
$result = call_user_func_array($callable, $parameters);
return $result;
}
}
class_alias('SimplePie\Registry', 'SimplePie_Registry');
src/Parser.php 0000644 00000104064 15143517255 0007315 0 ustar 00 */
public $data = [];
/** @var array> */
public $datas = [[]];
/** @var int */
public $current_xhtml_construct = -1;
/** @var string */
public $encoding;
/** @var Registry */
protected $registry;
/**
* @return void
*/
public function set_registry(\SimplePie\Registry $registry)
{
$this->registry = $registry;
}
/**
* @return bool
*/
public function parse(string &$data, string $encoding, string $url = '')
{
if (class_exists('DOMXpath') && function_exists('Mf2\parse')) {
$doc = new \DOMDocument();
@$doc->loadHTML($data);
$xpath = new \DOMXpath($doc);
// Check for both h-feed and h-entry, as both a feed with no entries
// and a list of entries without an h-feed wrapper are both valid.
$query = '//*[contains(concat(" ", @class, " "), " h-feed ") or '.
'contains(concat(" ", @class, " "), " h-entry ")]';
/** @var \DOMNodeList<\DOMElement> $result */
$result = $xpath->query($query);
if ($result->length !== 0) {
return $this->parse_microformats($data, $url);
}
}
// Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
if (strtoupper($encoding) === 'US-ASCII') {
$this->encoding = 'UTF-8';
} else {
$this->encoding = $encoding;
}
// Strip BOM:
// UTF-32 Big Endian BOM
if (substr($data, 0, 4) === "\x00\x00\xFE\xFF") {
$data = substr($data, 4);
}
// UTF-32 Little Endian BOM
elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00") {
$data = substr($data, 4);
}
// UTF-16 Big Endian BOM
elseif (substr($data, 0, 2) === "\xFE\xFF") {
$data = substr($data, 2);
}
// UTF-16 Little Endian BOM
elseif (substr($data, 0, 2) === "\xFF\xFE") {
$data = substr($data, 2);
}
// UTF-8 BOM
elseif (substr($data, 0, 3) === "\xEF\xBB\xBF") {
$data = substr($data, 3);
}
if (substr($data, 0, 5) === '')) !== false) {
$declaration = $this->registry->create(DeclarationParser::class, [substr($data, 5, $pos - 5)]);
if ($declaration->parse()) {
$data = substr($data, $pos + 2);
$data = 'version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . "\n" .
self::set_doctype($data);
} else {
$this->error_string = 'SimplePie bug! Please report this!';
return false;
}
} else {
$data = self::set_doctype($data);
}
$return = true;
static $xml_is_sane = null;
if ($xml_is_sane === null) {
$parser_check = xml_parser_create();
xml_parse_into_struct($parser_check, '&', $values);
if (\PHP_VERSION_ID < 80000) {
xml_parser_free($parser_check);
}
$xml_is_sane = isset($values[0]['value']);
}
// Create the parser
if ($xml_is_sane) {
$xml = xml_parser_create_ns($this->encoding, $this->separator);
xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
xml_set_character_data_handler($xml, [$this, 'cdata']);
xml_set_element_handler($xml, [$this, 'tag_open'], [$this, 'tag_close']);
// Parse!
$wrapper = @is_writable(sys_get_temp_dir()) ? 'php://temp' : 'php://memory';
if (($stream = fopen($wrapper, 'r+')) &&
fwrite($stream, $data) &&
rewind($stream)) {
//Parse by chunks not to use too much memory
do {
$stream_data = (string) fread($stream, 1048576);
if (!xml_parse($xml, $stream_data, feof($stream))) {
$this->error_code = xml_get_error_code($xml);
$this->error_string = xml_error_string($this->error_code) ?: "Unknown";
$return = false;
break;
}
} while (!feof($stream));
fclose($stream);
} else {
$return = false;
}
$this->current_line = xml_get_current_line_number($xml);
$this->current_column = xml_get_current_column_number($xml);
$this->current_byte = xml_get_current_byte_index($xml);
if (\PHP_VERSION_ID < 80000) {
xml_parser_free($xml);
}
return $return;
}
libxml_clear_errors();
$xml = new \XMLReader();
$xml->xml($data);
while (@$xml->read()) {
switch ($xml->nodeType) {
case \XMLReader::END_ELEMENT:
if ($xml->namespaceURI !== '') {
$tagName = $xml->namespaceURI . $this->separator . $xml->localName;
} else {
$tagName = $xml->localName;
}
$this->tag_close(null, $tagName);
break;
case \XMLReader::ELEMENT:
$empty = $xml->isEmptyElement;
if ($xml->namespaceURI !== '') {
$tagName = $xml->namespaceURI . $this->separator . $xml->localName;
} else {
$tagName = $xml->localName;
}
$attributes = [];
while ($xml->moveToNextAttribute()) {
if ($xml->namespaceURI !== '') {
$attrName = $xml->namespaceURI . $this->separator . $xml->localName;
} else {
$attrName = $xml->localName;
}
$attributes[$attrName] = $xml->value;
}
$this->tag_open(null, $tagName, $attributes);
if ($empty) {
$this->tag_close(null, $tagName);
}
break;
case \XMLReader::TEXT:
case \XMLReader::CDATA:
$this->cdata(null, $xml->value);
break;
}
}
if ($error = libxml_get_last_error()) {
$this->error_code = $error->code;
$this->error_string = $error->message;
$this->current_line = $error->line;
$this->current_column = $error->column;
return false;
}
return true;
}
/**
* @return int
*/
public function get_error_code()
{
return $this->error_code;
}
/**
* @return string
*/
public function get_error_string()
{
return $this->error_string;
}
/**
* @return int
*/
public function get_current_line()
{
return $this->current_line;
}
/**
* @return int
*/
public function get_current_column()
{
return $this->current_column;
}
/**
* @return int
*/
public function get_current_byte()
{
return $this->current_byte;
}
/**
* @return array
*/
public function get_data()
{
return $this->data;
}
/**
* @param XMLParser|resource|null $parser
* @param array $attributes
* @return void
*/
public function tag_open($parser, string $tag, array $attributes)
{
[$this->namespace[], $this->element[]] = $this->split_ns($tag);
$attribs = [];
foreach ($attributes as $name => $value) {
[$attrib_namespace, $attribute] = $this->split_ns($name);
$attribs[$attrib_namespace][$attribute] = $value;
}
if (isset($attribs[\SimplePie\SimplePie::NAMESPACE_XML]['base'])) {
$base = $this->registry->call(Misc::class, 'absolutize_url', [$attribs[\SimplePie\SimplePie::NAMESPACE_XML]['base'], end($this->xml_base)]);
if ($base !== false) {
$this->xml_base[] = $base;
$this->xml_base_explicit[] = true;
}
} else {
$this->xml_base[] = end($this->xml_base) ?: '';
$this->xml_base_explicit[] = end($this->xml_base_explicit);
}
if (isset($attribs[\SimplePie\SimplePie::NAMESPACE_XML]['lang'])) {
$this->xml_lang[] = $attribs[\SimplePie\SimplePie::NAMESPACE_XML]['lang'];
} else {
$this->xml_lang[] = end($this->xml_lang) ?: '';
}
if ($this->current_xhtml_construct >= 0) {
$this->current_xhtml_construct++;
if (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_XHTML) {
$this->data['data'] .= '<' . end($this->element);
if (isset($attribs[''])) {
foreach ($attribs[''] as $name => $value) {
$this->data['data'] .= ' ' . $name . '="' . htmlspecialchars($value, ENT_COMPAT, $this->encoding) . '"';
}
}
$this->data['data'] .= '>';
}
} else {
$this->datas[] = &$this->data;
$this->data = &$this->data['child'][end($this->namespace)][end($this->element)][];
$this->data = ['data' => '', 'attribs' => $attribs, 'xml_base' => end($this->xml_base), 'xml_base_explicit' => end($this->xml_base_explicit), 'xml_lang' => end($this->xml_lang)];
if ((end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_ATOM_03 && in_array(end($this->element), ['title', 'tagline', 'copyright', 'info', 'summary', 'content']) && isset($attribs['']['mode']) && $attribs['']['mode'] === 'xml')
|| (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_ATOM_10 && in_array(end($this->element), ['rights', 'subtitle', 'summary', 'info', 'title', 'content']) && isset($attribs['']['type']) && $attribs['']['type'] === 'xhtml')
|| (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_RSS_20 && in_array(end($this->element), ['title']))
|| (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_RSS_090 && in_array(end($this->element), ['title']))
|| (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_RSS_10 && in_array(end($this->element), ['title']))) {
$this->current_xhtml_construct = 0;
}
}
}
/**
* @param XMLParser|resource|null $parser
* @return void
*/
public function cdata($parser, string $cdata)
{
if ($this->current_xhtml_construct >= 0) {
$this->data['data'] .= htmlspecialchars($cdata, ENT_QUOTES, $this->encoding);
} else {
$this->data['data'] .= $cdata;
}
}
/**
* @param XMLParser|resource|null $parser
* @return void
*/
public function tag_close($parser, string $tag)
{
if ($this->current_xhtml_construct >= 0) {
$this->current_xhtml_construct--;
if (end($this->namespace) === \SimplePie\SimplePie::NAMESPACE_XHTML && !in_array(end($this->element), ['area', 'base', 'basefont', 'br', 'col', 'frame', 'hr', 'img', 'input', 'isindex', 'link', 'meta', 'param'])) {
$this->data['data'] .= '' . end($this->element) . '>';
}
}
if ($this->current_xhtml_construct === -1) {
$this->data = &$this->datas[count($this->datas) - 1];
array_pop($this->datas);
}
array_pop($this->element);
array_pop($this->namespace);
array_pop($this->xml_base);
array_pop($this->xml_base_explicit);
array_pop($this->xml_lang);
}
/**
* @return array{string, string}
*/
public function split_ns(string $string)
{
static $cache = [];
if (!isset($cache[$string])) {
if ($pos = strpos($string, $this->separator)) {
static $separator_length;
if (!$separator_length) {
$separator_length = strlen($this->separator);
}
$namespace = substr($string, 0, $pos);
$local_name = substr($string, $pos + $separator_length);
if (strtolower($namespace) === \SimplePie\SimplePie::NAMESPACE_ITUNES) {
$namespace = \SimplePie\SimplePie::NAMESPACE_ITUNES;
}
// Normalize the Media RSS namespaces
if ($namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG ||
$namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG2 ||
$namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG3 ||
$namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG4 ||
$namespace === \SimplePie\SimplePie::NAMESPACE_MEDIARSS_WRONG5) {
$namespace = \SimplePie\SimplePie::NAMESPACE_MEDIARSS;
}
$cache[$string] = [$namespace, $local_name];
} else {
$cache[$string] = ['', $string];
}
}
return $cache[$string];
}
/**
* @param array $data
*/
private function parse_hcard(array $data, bool $category = false): string
{
$name = '';
$link = '';
// Check if h-card is set and pass that information on in the link.
if (isset($data['type']) && in_array('h-card', $data['type'])) {
if (isset($data['properties']['name'][0])) {
$name = $data['properties']['name'][0];
}
if (isset($data['properties']['url'][0])) {
$link = $data['properties']['url'][0];
if ($name === '') {
$name = $link;
} else {
// can't have commas in categories.
$name = str_replace(',', '', $name);
}
$person_tag = $category ? '' : '';
return ''.$person_tag.$name.'';
}
}
return $data['value'] ?? '';
}
/**
* @return true
*/
private function parse_microformats(string &$data, string $url): bool
{
// For PHPStan, we already check that in call site.
\assert(function_exists('Mf2\parse'));
\assert(function_exists('Mf2\fetch'));
$feed_title = '';
$feed_author = null;
$author_cache = [];
$items = [];
$entries = [];
$mf = \Mf2\parse($data, $url);
// First look for an h-feed.
$h_feed = [];
foreach ($mf['items'] as $mf_item) {
if (in_array('h-feed', $mf_item['type'])) {
$h_feed = $mf_item;
break;
}
// Also look for h-feed or h-entry in the children of each top level item.
if (!isset($mf_item['children'][0]['type'])) {
continue;
}
if (in_array('h-feed', $mf_item['children'][0]['type'])) {
$h_feed = $mf_item['children'][0];
// In this case the parent of the h-feed may be an h-card, so use it as
// the feed_author.
if (in_array('h-card', $mf_item['type'])) {
$feed_author = $mf_item;
}
break;
} elseif (in_array('h-entry', $mf_item['children'][0]['type'])) {
$entries = $mf_item['children'];
// In this case the parent of the h-entry list may be an h-card, so use
// it as the feed_author.
if (in_array('h-card', $mf_item['type'])) {
$feed_author = $mf_item;
}
break;
}
}
if (isset($h_feed['children'])) {
$entries = $h_feed['children'];
// Also set the feed title and store author from the h-feed if available.
if (isset($mf['items'][0]['properties']['name'][0])) {
$feed_title = $mf['items'][0]['properties']['name'][0];
}
if (isset($mf['items'][0]['properties']['author'][0])) {
$feed_author = $mf['items'][0]['properties']['author'][0];
}
} elseif (count($entries) === 0) {
$entries = $mf['items'];
}
for ($i = 0; $i < count($entries); $i++) {
$entry = $entries[$i];
if (in_array('h-entry', $entry['type'])) {
$item = [];
$title = '';
$description = '';
if (isset($entry['properties']['url'][0])) {
$link = $entry['properties']['url'][0];
if (isset($link['value'])) {
$link = $link['value'];
}
$item['link'] = [['data' => $link]];
}
if (isset($entry['properties']['uid'][0])) {
$guid = $entry['properties']['uid'][0];
if (isset($guid['value'])) {
$guid = $guid['value'];
}
$item['guid'] = [['data' => $guid]];
}
if (isset($entry['properties']['name'][0])) {
$title = $entry['properties']['name'][0];
if (isset($title['value'])) {
$title = $title['value'];
}
$item['title'] = [['data' => $title]];
}
if (isset($entry['properties']['author'][0]) || isset($feed_author)) {
// author is a special case, it can be plain text or an h-card array.
// If it's plain text it can also be a url that should be followed to
// get the actual h-card.
$author = $entry['properties']['author'][0] ?? $feed_author;
if (!is_string($author)) {
$author = $this->parse_hcard($author);
} elseif (strpos($author, 'http') === 0) {
if (isset($author_cache[$author])) {
$author = $author_cache[$author];
} else {
if ($mf = \Mf2\fetch($author)) {
foreach ($mf['items'] as $hcard) {
// Only interested in an h-card by itself in this case.
if (!in_array('h-card', $hcard['type'])) {
continue;
}
// It must have a url property matching what we fetched.
if (!isset($hcard['properties']['url']) ||
!(in_array($author, $hcard['properties']['url']))) {
continue;
}
// Save parse_hcard the trouble of finding the correct url.
$hcard['properties']['url'][0] = $author;
// Cache this h-card for the next h-entry to check.
$author_cache[$author] = $this->parse_hcard($hcard);
$author = $author_cache[$author];
break;
}
}
}
}
$item['author'] = [['data' => $author]];
}
if (isset($entry['properties']['photo'][0])) {
// If a photo is also in content, don't need to add it again here.
$content = '';
if (isset($entry['properties']['content'][0]['html'])) {
$content = $entry['properties']['content'][0]['html'];
}
$photo_list = [];
for ($j = 0; $j < count($entry['properties']['photo']); $j++) {
$photo = $entry['properties']['photo'][$j];
if (!empty($photo) && strpos($content, $photo) === false) {
$photo_list[] = $photo;
}
}
// When there's more than one photo show the first and use a lightbox.
// Need a permanent, unique name for the image set, but don't have
// anything unique except for the content itself, so use that.
$count = count($photo_list);
if ($count > 1) {
$image_set_id = preg_replace('/[[:^alnum:]]/', '', $photo_list[0]);
$description = '
';
}
}
if (isset($entry['properties']['content'][0]['html'])) {
// e-content['value'] is the same as p-name when they are on the same
// element. Use this to replace title with a strip_tags version so
// that alt text from images is not included in the title.
if ($entry['properties']['content'][0]['value'] === $title) {
$title = strip_tags($entry['properties']['content'][0]['html']);
$item['title'] = [['data' => $title]];
}
$description .= $entry['properties']['content'][0]['html'];
if (isset($entry['properties']['in-reply-to'][0])) {
$in_reply_to = '';
if (is_string($entry['properties']['in-reply-to'][0])) {
$in_reply_to = $entry['properties']['in-reply-to'][0];
} elseif (isset($entry['properties']['in-reply-to'][0]['value'])) {
$in_reply_to = $entry['properties']['in-reply-to'][0]['value'];
}
if ($in_reply_to !== '') {
$description .= '
';
}
}
$item['description'] = [['data' => $description]];
}
if (isset($entry['properties']['category'])) {
$category_csv = '';
// Categories can also contain h-cards.
foreach ($entry['properties']['category'] as $category) {
if ($category_csv !== '') {
$category_csv .= ', ';
}
if (is_string($category)) {
// Can't have commas in categories.
$category_csv .= str_replace(',', '', $category);
} else {
$category_csv .= $this->parse_hcard($category, true);
}
}
$item['category'] = [['data' => $category_csv]];
}
if (isset($entry['properties']['published'][0])) {
$timestamp = strtotime($entry['properties']['published'][0]);
$pub_date = date('F j Y g:ia', $timestamp).' GMT';
$item['pubDate'] = [['data' => $pub_date]];
}
// The title and description are set to the empty string to represent
// a deleted item (which also makes it an invalid rss item).
if (isset($entry['properties']['deleted'][0])) {
$item['title'] = [['data' => '']];
$item['description'] = [['data' => '']];
}
$items[] = ['child' => ['' => $item]];
}
}
// Mimic RSS data format when storing microformats.
$link = [['data' => $url]];
$image = '';
if (!is_string($feed_author) &&
isset($feed_author['properties']['photo'][0])) {
$image = [['child' => ['' => ['url' =>
[['data' => $feed_author['properties']['photo'][0]]]]]]];
}
// Use the name given for the h-feed, or get the title from the html.
if ($feed_title !== '') {
$feed_title = [['data' => htmlspecialchars($feed_title)]];
} elseif ($position = strpos($data, '
')) {
$start = $position < 200 ? 0 : $position - 200;
$check = substr($data, $start, 400);
$matches = [];
if (preg_match('/(.+)<\/title>/', $check, $matches)) {
$feed_title = [['data' => htmlspecialchars($matches[1])]];
}
}
$channel = ['channel' => [['child' => ['' =>
['link' => $link, 'image' => $image, 'title' => $feed_title,
'item' => $items]]]]];
$rss = [['attribs' => ['' => ['version' => '2.0']],
'child' => ['' => $channel]]];
$this->data = ['child' => ['' => ['rss' => $rss]]];
return true;
}
private static function set_doctype(string $data): string
{
// Strip DOCTYPE except if containing an [internal subset]
$data = preg_replace('/^\\s*\\[\\]]*>\s*/', '', $data) ?? $data;
// Declare HTML entities only if no remaining DOCTYPE
$doctype = preg_match('/^\\s* ]>';
}
}
class_alias('SimplePie\Parser', 'SimplePie_Parser');
src/Misc.php 0000644 00000210245 15143517255 0006753 0 ustar 00 0) {
$time .= $hours.':';
}
$minutes = floor($remainder / 60);
$seconds = $remainder % 60;
if ($minutes < 10 && $hours > 0) {
$minutes = '0' . $minutes;
}
if ($seconds < 10) {
$seconds = '0' . $seconds;
}
$time .= $minutes.':';
$time .= $seconds;
return $time;
}
/**
* @return string|false
*/
public static function absolutize_url(string $relative, string $base)
{
$iri = \SimplePie\IRI::absolutize(new \SimplePie\IRI($base), $relative);
if ($iri === false) {
return false;
}
return $iri->get_uri();
}
/**
* @internal
*/
public static function is_remote_uri(string $uri): bool
{
return preg_match('/^https?:\/\//i', $uri) === 1;
}
/**
* Get a HTML/XML element from a HTML string
*
* @deprecated since SimplePie 1.3, use DOMDocument instead (parsing HTML with regex is bad!)
* @param string $realname Element name (including namespace prefix if applicable)
* @param string $string HTML document
* @return array, content?: string}>
*/
public static function get_element(string $realname, string $string)
{
// trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.3, use "DOMDocument" instead.'), \E_USER_DEPRECATED);
$return = [];
$name = preg_quote($realname, '/');
if (preg_match_all("/<($name)" . \SimplePie\SimplePie::PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE)) {
for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++) {
$return[$i]['tag'] = $realname;
$return[$i]['full'] = $matches[$i][0][0];
$return[$i]['offset'] = $matches[$i][0][1];
if (strlen($matches[$i][3][0]) <= 2) {
$return[$i]['self_closing'] = true;
} else {
$return[$i]['self_closing'] = false;
$return[$i]['content'] = $matches[$i][4][0];
}
$return[$i]['attribs'] = [];
if (isset($matches[$i][2][0]) && preg_match_all('/[\x09\x0A\x0B\x0C\x0D\x20]+([^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*)(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"([^"]*)"|\'([^\']*)\'|([^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?/', ' ' . $matches[$i][2][0] . ' ', $attribs, PREG_SET_ORDER)) {
foreach ($attribs as $attrib) {
if (count($attrib) === 2) {
$attrib[2] = $attrib[1];
}
$return[$i]['attribs'][strtolower($attrib[1])]['data'] = Misc::entities_decode(end($attrib));
}
}
}
}
return $return;
}
/**
* @deprecated since SimplePie 1.9.0. If you need it, you can copy the function to your codebase. But you should consider using `DOMDocument` for any DOM wrangling.
* @param array{tag: string, self_closing: bool, attribs: array, content: string} $element
* @return string
*/
public static function element_implode(array $element)
{
// trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.9.'), \E_USER_DEPRECATED);
$full = "<{$element['tag']}";
foreach ($element['attribs'] as $key => $value) {
$key = strtolower($key);
$full .= " $key=\"" . htmlspecialchars($value['data'], ENT_COMPAT, 'UTF-8') . '"';
}
if ($element['self_closing']) {
$full .= ' />';
} else {
$full .= ">{$element['content']}{$element['tag']}>";
}
return $full;
}
/**
* @param string $message
* @param int $level
* @param string $file
* @param int $line
* @return string
*/
public static function error(string $message, int $level, string $file, int $line)
{
if ((error_reporting() & $level) > 0) {
switch ($level) {
case E_USER_ERROR:
$note = 'PHP Error';
break;
case E_USER_WARNING:
$note = 'PHP Warning';
break;
case E_USER_NOTICE:
$note = 'PHP Notice';
break;
default:
$note = 'Unknown Error';
break;
}
$log_error = true;
if (!function_exists('error_log')) {
$log_error = false;
}
$log_file = @ini_get('error_log');
if (!empty($log_file) && ('syslog' !== $log_file) && !@is_writable($log_file)) {
$log_error = false;
}
if ($log_error) {
@error_log("$note: $message in $file on line $line", 0);
}
}
return $message;
}
/**
* @return string
*/
public static function fix_protocol(string $url, int $http = 1)
{
$url = Misc::normalize_url($url);
$parsed = Misc::parse_url($url);
if ($parsed['scheme'] !== '' && $parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https') {
return Misc::fix_protocol(Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http);
}
if ($parsed['scheme'] === '' && $parsed['authority'] === '' && !file_exists($url)) {
return Misc::fix_protocol(Misc::compress_parse_url('http', $parsed['path'], '', $parsed['query'], $parsed['fragment']), $http);
}
if ($http === 2 && $parsed['scheme'] !== '') {
return "feed:$url";
} elseif ($http === 3 && strtolower($parsed['scheme']) === 'http') {
return substr_replace($url, 'podcast', 0, 4);
} elseif ($http === 4 && strtolower($parsed['scheme']) === 'http') {
return substr_replace($url, 'itpc', 0, 4);
}
return $url;
}
/**
* @deprecated since SimplePie 1.8.0, use PHP native array_replace_recursive() instead.
* @param array $array1
* @param array $array2
* @return array
*/
public static function array_merge_recursive(array $array1, array $array2)
{
foreach ($array2 as $key => $value) {
if (is_array($value)) {
$array1[$key] = Misc::array_merge_recursive($array1[$key], $value);
} else {
$array1[$key] = $value;
}
}
return $array1;
}
/**
* @return array
*/
public static function parse_url(string $url)
{
$iri = new \SimplePie\IRI($url);
return [
'scheme' => (string) $iri->scheme,
'authority' => (string) $iri->authority,
'path' => (string) $iri->path,
'query' => (string) $iri->query,
'fragment' => (string) $iri->fragment
];
}
/**
* @return string
*/
public static function compress_parse_url(string $scheme = '', string $authority = '', string $path = '', string $query = '', ?string $fragment = '')
{
$iri = new \SimplePie\IRI('');
$iri->scheme = $scheme;
$iri->authority = $authority;
$iri->path = $path;
$iri->query = $query;
$iri->fragment = $fragment;
return $iri->get_uri();
}
/**
* @return string
*/
public static function normalize_url(string $url)
{
$iri = new \SimplePie\IRI($url);
return $iri->get_uri();
}
/**
* @deprecated since SimplePie 1.9.0. This functionality is part of `IRI` – if you need it standalone, consider copying the function to your codebase.
* @param array $match
* @return string
*/
public static function percent_encoding_normalization(array $match)
{
$integer = hexdec($match[1]);
if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer === 0x2D || $integer === 0x2E || $integer === 0x5F || $integer === 0x7E) {
// Cast for PHPStan, the value would only be float when above PHP_INT_MAX, which would not go in this branch.
return chr((int) $integer);
}
return strtoupper($match[0]);
}
/**
* Converts a Windows-1252 encoded string to a UTF-8 encoded string
*
* @static
* @param string $string Windows-1252 encoded string
* @return string UTF-8 encoded string
*/
public static function windows_1252_to_utf8(string $string)
{
static $convert_table = ["\x80" => "\xE2\x82\xAC", "\x81" => "\xEF\xBF\xBD", "\x82" => "\xE2\x80\x9A", "\x83" => "\xC6\x92", "\x84" => "\xE2\x80\x9E", "\x85" => "\xE2\x80\xA6", "\x86" => "\xE2\x80\xA0", "\x87" => "\xE2\x80\xA1", "\x88" => "\xCB\x86", "\x89" => "\xE2\x80\xB0", "\x8A" => "\xC5\xA0", "\x8B" => "\xE2\x80\xB9", "\x8C" => "\xC5\x92", "\x8D" => "\xEF\xBF\xBD", "\x8E" => "\xC5\xBD", "\x8F" => "\xEF\xBF\xBD", "\x90" => "\xEF\xBF\xBD", "\x91" => "\xE2\x80\x98", "\x92" => "\xE2\x80\x99", "\x93" => "\xE2\x80\x9C", "\x94" => "\xE2\x80\x9D", "\x95" => "\xE2\x80\xA2", "\x96" => "\xE2\x80\x93", "\x97" => "\xE2\x80\x94", "\x98" => "\xCB\x9C", "\x99" => "\xE2\x84\xA2", "\x9A" => "\xC5\xA1", "\x9B" => "\xE2\x80\xBA", "\x9C" => "\xC5\x93", "\x9D" => "\xEF\xBF\xBD", "\x9E" => "\xC5\xBE", "\x9F" => "\xC5\xB8", "\xA0" => "\xC2\xA0", "\xA1" => "\xC2\xA1", "\xA2" => "\xC2\xA2", "\xA3" => "\xC2\xA3", "\xA4" => "\xC2\xA4", "\xA5" => "\xC2\xA5", "\xA6" => "\xC2\xA6", "\xA7" => "\xC2\xA7", "\xA8" => "\xC2\xA8", "\xA9" => "\xC2\xA9", "\xAA" => "\xC2\xAA", "\xAB" => "\xC2\xAB", "\xAC" => "\xC2\xAC", "\xAD" => "\xC2\xAD", "\xAE" => "\xC2\xAE", "\xAF" => "\xC2\xAF", "\xB0" => "\xC2\xB0", "\xB1" => "\xC2\xB1", "\xB2" => "\xC2\xB2", "\xB3" => "\xC2\xB3", "\xB4" => "\xC2\xB4", "\xB5" => "\xC2\xB5", "\xB6" => "\xC2\xB6", "\xB7" => "\xC2\xB7", "\xB8" => "\xC2\xB8", "\xB9" => "\xC2\xB9", "\xBA" => "\xC2\xBA", "\xBB" => "\xC2\xBB", "\xBC" => "\xC2\xBC", "\xBD" => "\xC2\xBD", "\xBE" => "\xC2\xBE", "\xBF" => "\xC2\xBF", "\xC0" => "\xC3\x80", "\xC1" => "\xC3\x81", "\xC2" => "\xC3\x82", "\xC3" => "\xC3\x83", "\xC4" => "\xC3\x84", "\xC5" => "\xC3\x85", "\xC6" => "\xC3\x86", "\xC7" => "\xC3\x87", "\xC8" => "\xC3\x88", "\xC9" => "\xC3\x89", "\xCA" => "\xC3\x8A", "\xCB" => "\xC3\x8B", "\xCC" => "\xC3\x8C", "\xCD" => "\xC3\x8D", "\xCE" => "\xC3\x8E", "\xCF" => "\xC3\x8F", "\xD0" => "\xC3\x90", "\xD1" => "\xC3\x91", "\xD2" => "\xC3\x92", "\xD3" => "\xC3\x93", "\xD4" => "\xC3\x94", "\xD5" => "\xC3\x95", "\xD6" => "\xC3\x96", "\xD7" => "\xC3\x97", "\xD8" => "\xC3\x98", "\xD9" => "\xC3\x99", "\xDA" => "\xC3\x9A", "\xDB" => "\xC3\x9B", "\xDC" => "\xC3\x9C", "\xDD" => "\xC3\x9D", "\xDE" => "\xC3\x9E", "\xDF" => "\xC3\x9F", "\xE0" => "\xC3\xA0", "\xE1" => "\xC3\xA1", "\xE2" => "\xC3\xA2", "\xE3" => "\xC3\xA3", "\xE4" => "\xC3\xA4", "\xE5" => "\xC3\xA5", "\xE6" => "\xC3\xA6", "\xE7" => "\xC3\xA7", "\xE8" => "\xC3\xA8", "\xE9" => "\xC3\xA9", "\xEA" => "\xC3\xAA", "\xEB" => "\xC3\xAB", "\xEC" => "\xC3\xAC", "\xED" => "\xC3\xAD", "\xEE" => "\xC3\xAE", "\xEF" => "\xC3\xAF", "\xF0" => "\xC3\xB0", "\xF1" => "\xC3\xB1", "\xF2" => "\xC3\xB2", "\xF3" => "\xC3\xB3", "\xF4" => "\xC3\xB4", "\xF5" => "\xC3\xB5", "\xF6" => "\xC3\xB6", "\xF7" => "\xC3\xB7", "\xF8" => "\xC3\xB8", "\xF9" => "\xC3\xB9", "\xFA" => "\xC3\xBA", "\xFB" => "\xC3\xBB", "\xFC" => "\xC3\xBC", "\xFD" => "\xC3\xBD", "\xFE" => "\xC3\xBE", "\xFF" => "\xC3\xBF"];
return strtr($string, $convert_table);
}
/**
* Change a string from one encoding to another
*
* @param string $data Raw data in $input encoding
* @param string $input Encoding of $data
* @param string $output Encoding you want
* @return string|false False if we can't convert it
*/
public static function change_encoding(string $data, string $input, string $output)
{
$input = Misc::encoding($input);
$output = Misc::encoding($output);
// We fail to fail on non US-ASCII bytes
if ($input === 'US-ASCII') {
static $non_ascii_octets = '';
if (!$non_ascii_octets) {
for ($i = 0x80; $i <= 0xFF; $i++) {
$non_ascii_octets .= chr($i);
}
}
$data = substr($data, 0, strcspn($data, $non_ascii_octets));
}
// This is first, as behaviour of this is completely predictable
if ($input === 'windows-1252' && $output === 'UTF-8') {
return Misc::windows_1252_to_utf8($data);
}
// This is second, as behaviour of this varies only with PHP version (the middle part of this expression checks the encoding is supported).
elseif (function_exists('mb_convert_encoding') && ($return = Misc::change_encoding_mbstring($data, $input, $output))) {
return $return;
}
// This is third, as behaviour of this varies with OS userland and PHP version
elseif (function_exists('iconv') && ($return = Misc::change_encoding_iconv($data, $input, $output))) {
return $return;
}
// This is last, as behaviour of this varies with OS userland and PHP version
elseif (class_exists('\UConverter') && ($return = Misc::change_encoding_uconverter($data, $input, $output))) {
return $return;
}
// If we can't do anything, just fail
return false;
}
/**
* @return string|false
*/
protected static function change_encoding_mbstring(string $data, string $input, string $output)
{
if ($input === 'windows-949') {
$input = 'EUC-KR';
}
if ($output === 'windows-949') {
$output = 'EUC-KR';
}
if ($input === 'Windows-31J') {
$input = 'SJIS';
}
if ($output === 'Windows-31J') {
$output = 'SJIS';
}
// Check that the encoding is supported
if (!in_array($input, mb_list_encodings())) {
return false;
}
if (@mb_convert_encoding("\x80", 'UTF-16BE', $input) === "\x00\x80") {
return false;
}
// Let's do some conversion
if ($return = @mb_convert_encoding($data, $output, $input)) {
return $return;
}
return false;
}
/**
* @return string|false
*/
protected static function change_encoding_iconv(string $data, string $input, string $output)
{
return @iconv($input, $output, $data);
}
/**
* @return string|false
*/
protected static function change_encoding_uconverter(string $data, string $input, string $output)
{
return @\UConverter::transcode($data, $output, $input);
}
/**
* Normalize an encoding name
*
* This is automatically generated by create.php
*
* To generate it, run `php create.php` on the command line, and copy the
* output to replace this function.
*
* @param string $charset Character set to standardise
* @return string Standardised name
*/
public static function encoding(string $charset)
{
// Normalization from UTS #22
// Cast for PHPStan, the regex should not fail.
switch (strtolower((string) preg_replace('/(?:[^a-zA-Z0-9]+|([^0-9])0+)/', '\1', $charset))) {
case 'adobestandardencoding':
case 'csadobestandardencoding':
return 'Adobe-Standard-Encoding';
case 'adobesymbolencoding':
case 'cshppsmath':
return 'Adobe-Symbol-Encoding';
case 'ami1251':
case 'amiga1251':
return 'Amiga-1251';
case 'ansix31101983':
case 'csat5001983':
case 'csiso99naplps':
case 'isoir99':
case 'naplps':
return 'ANSI_X3.110-1983';
case 'arabic7':
case 'asmo449':
case 'csiso89asmo449':
case 'iso9036':
case 'isoir89':
return 'ASMO_449';
case 'big5':
case 'csbig5':
return 'Big5';
case 'big5hkscs':
return 'Big5-HKSCS';
case 'bocu1':
case 'csbocu1':
return 'BOCU-1';
case 'brf':
case 'csbrf':
return 'BRF';
case 'bs4730':
case 'csiso4unitedkingdom':
case 'gb':
case 'iso646gb':
case 'isoir4':
case 'uk':
return 'BS_4730';
case 'bsviewdata':
case 'csiso47bsviewdata':
case 'isoir47':
return 'BS_viewdata';
case 'cesu8':
case 'cscesu8':
return 'CESU-8';
case 'ca':
case 'csa71':
case 'csaz243419851':
case 'csiso121canadian1':
case 'iso646ca':
case 'isoir121':
return 'CSA_Z243.4-1985-1';
case 'csa72':
case 'csaz243419852':
case 'csiso122canadian2':
case 'iso646ca2':
case 'isoir122':
return 'CSA_Z243.4-1985-2';
case 'csaz24341985gr':
case 'csiso123csaz24341985gr':
case 'isoir123':
return 'CSA_Z243.4-1985-gr';
case 'csiso139csn369103':
case 'csn369103':
case 'isoir139':
return 'CSN_369103';
case 'csdecmcs':
case 'dec':
case 'decmcs':
return 'DEC-MCS';
case 'csiso21german':
case 'de':
case 'din66003':
case 'iso646de':
case 'isoir21':
return 'DIN_66003';
case 'csdkus':
case 'dkus':
return 'dk-us';
case 'csiso646danish':
case 'dk':
case 'ds2089':
case 'iso646dk':
return 'DS_2089';
case 'csibmebcdicatde':
case 'ebcdicatde':
return 'EBCDIC-AT-DE';
case 'csebcdicatdea':
case 'ebcdicatdea':
return 'EBCDIC-AT-DE-A';
case 'csebcdiccafr':
case 'ebcdiccafr':
return 'EBCDIC-CA-FR';
case 'csebcdicdkno':
case 'ebcdicdkno':
return 'EBCDIC-DK-NO';
case 'csebcdicdknoa':
case 'ebcdicdknoa':
return 'EBCDIC-DK-NO-A';
case 'csebcdices':
case 'ebcdices':
return 'EBCDIC-ES';
case 'csebcdicesa':
case 'ebcdicesa':
return 'EBCDIC-ES-A';
case 'csebcdicess':
case 'ebcdicess':
return 'EBCDIC-ES-S';
case 'csebcdicfise':
case 'ebcdicfise':
return 'EBCDIC-FI-SE';
case 'csebcdicfisea':
case 'ebcdicfisea':
return 'EBCDIC-FI-SE-A';
case 'csebcdicfr':
case 'ebcdicfr':
return 'EBCDIC-FR';
case 'csebcdicit':
case 'ebcdicit':
return 'EBCDIC-IT';
case 'csebcdicpt':
case 'ebcdicpt':
return 'EBCDIC-PT';
case 'csebcdicuk':
case 'ebcdicuk':
return 'EBCDIC-UK';
case 'csebcdicus':
case 'ebcdicus':
return 'EBCDIC-US';
case 'csiso111ecmacyrillic':
case 'ecmacyrillic':
case 'isoir111':
case 'koi8e':
return 'ECMA-cyrillic';
case 'csiso17spanish':
case 'es':
case 'iso646es':
case 'isoir17':
return 'ES';
case 'csiso85spanish2':
case 'es2':
case 'iso646es2':
case 'isoir85':
return 'ES2';
case 'cseucpkdfmtjapanese':
case 'eucjp':
case 'extendedunixcodepackedformatforjapanese':
return 'EUC-JP';
case 'cseucfixwidjapanese':
case 'extendedunixcodefixedwidthforjapanese':
return 'Extended_UNIX_Code_Fixed_Width_for_Japanese';
case 'gb18030':
return 'GB18030';
case 'chinese':
case 'cp936':
case 'csgb2312':
case 'csiso58gb231280':
case 'gb2312':
case 'gb231280':
case 'gbk':
case 'isoir58':
case 'ms936':
case 'windows936':
return 'GBK';
case 'cn':
case 'csiso57gb1988':
case 'gb198880':
case 'iso646cn':
case 'isoir57':
return 'GB_1988-80';
case 'csiso153gost1976874':
case 'gost1976874':
case 'isoir153':
case 'stsev35888':
return 'GOST_19768-74';
case 'csiso150':
case 'csiso150greekccitt':
case 'greekccitt':
case 'isoir150':
return 'greek-ccitt';
case 'csiso88greek7':
case 'greek7':
case 'isoir88':
return 'greek7';
case 'csiso18greek7old':
case 'greek7old':
case 'isoir18':
return 'greek7-old';
case 'cshpdesktop':
case 'hpdesktop':
return 'HP-DeskTop';
case 'cshplegal':
case 'hplegal':
return 'HP-Legal';
case 'cshpmath8':
case 'hpmath8':
return 'HP-Math8';
case 'cshppifont':
case 'hppifont':
return 'HP-Pi-font';
case 'cshproman8':
case 'hproman8':
case 'r8':
case 'roman8':
return 'hp-roman8';
case 'hzgb2312':
return 'HZ-GB-2312';
case 'csibmsymbols':
case 'ibmsymbols':
return 'IBM-Symbols';
case 'csibmthai':
case 'ibmthai':
return 'IBM-Thai';
case 'cp37':
case 'csibm37':
case 'ebcdiccpca':
case 'ebcdiccpnl':
case 'ebcdiccpus':
case 'ebcdiccpwt':
case 'ibm37':
return 'IBM037';
case 'cp38':
case 'csibm38':
case 'ebcdicint':
case 'ibm38':
return 'IBM038';
case 'cp273':
case 'csibm273':
case 'ibm273':
return 'IBM273';
case 'cp274':
case 'csibm274':
case 'ebcdicbe':
case 'ibm274':
return 'IBM274';
case 'cp275':
case 'csibm275':
case 'ebcdicbr':
case 'ibm275':
return 'IBM275';
case 'csibm277':
case 'ebcdiccpdk':
case 'ebcdiccpno':
case 'ibm277':
return 'IBM277';
case 'cp278':
case 'csibm278':
case 'ebcdiccpfi':
case 'ebcdiccpse':
case 'ibm278':
return 'IBM278';
case 'cp280':
case 'csibm280':
case 'ebcdiccpit':
case 'ibm280':
return 'IBM280';
case 'cp281':
case 'csibm281':
case 'ebcdicjpe':
case 'ibm281':
return 'IBM281';
case 'cp284':
case 'csibm284':
case 'ebcdiccpes':
case 'ibm284':
return 'IBM284';
case 'cp285':
case 'csibm285':
case 'ebcdiccpgb':
case 'ibm285':
return 'IBM285';
case 'cp290':
case 'csibm290':
case 'ebcdicjpkana':
case 'ibm290':
return 'IBM290';
case 'cp297':
case 'csibm297':
case 'ebcdiccpfr':
case 'ibm297':
return 'IBM297';
case 'cp420':
case 'csibm420':
case 'ebcdiccpar1':
case 'ibm420':
return 'IBM420';
case 'cp423':
case 'csibm423':
case 'ebcdiccpgr':
case 'ibm423':
return 'IBM423';
case 'cp424':
case 'csibm424':
case 'ebcdiccphe':
case 'ibm424':
return 'IBM424';
case '437':
case 'cp437':
case 'cspc8codepage437':
case 'ibm437':
return 'IBM437';
case 'cp500':
case 'csibm500':
case 'ebcdiccpbe':
case 'ebcdiccpch':
case 'ibm500':
return 'IBM500';
case 'cp775':
case 'cspc775baltic':
case 'ibm775':
return 'IBM775';
case '850':
case 'cp850':
case 'cspc850multilingual':
case 'ibm850':
return 'IBM850';
case '851':
case 'cp851':
case 'csibm851':
case 'ibm851':
return 'IBM851';
case '852':
case 'cp852':
case 'cspcp852':
case 'ibm852':
return 'IBM852';
case '855':
case 'cp855':
case 'csibm855':
case 'ibm855':
return 'IBM855';
case '857':
case 'cp857':
case 'csibm857':
case 'ibm857':
return 'IBM857';
case 'ccsid858':
case 'cp858':
case 'ibm858':
case 'pcmultilingual850euro':
return 'IBM00858';
case '860':
case 'cp860':
case 'csibm860':
case 'ibm860':
return 'IBM860';
case '861':
case 'cp861':
case 'cpis':
case 'csibm861':
case 'ibm861':
return 'IBM861';
case '862':
case 'cp862':
case 'cspc862latinhebrew':
case 'ibm862':
return 'IBM862';
case '863':
case 'cp863':
case 'csibm863':
case 'ibm863':
return 'IBM863';
case 'cp864':
case 'csibm864':
case 'ibm864':
return 'IBM864';
case '865':
case 'cp865':
case 'csibm865':
case 'ibm865':
return 'IBM865';
case '866':
case 'cp866':
case 'csibm866':
case 'ibm866':
return 'IBM866';
case 'cp868':
case 'cpar':
case 'csibm868':
case 'ibm868':
return 'IBM868';
case '869':
case 'cp869':
case 'cpgr':
case 'csibm869':
case 'ibm869':
return 'IBM869';
case 'cp870':
case 'csibm870':
case 'ebcdiccproece':
case 'ebcdiccpyu':
case 'ibm870':
return 'IBM870';
case 'cp871':
case 'csibm871':
case 'ebcdiccpis':
case 'ibm871':
return 'IBM871';
case 'cp880':
case 'csibm880':
case 'ebcdiccyrillic':
case 'ibm880':
return 'IBM880';
case 'cp891':
case 'csibm891':
case 'ibm891':
return 'IBM891';
case 'cp903':
case 'csibm903':
case 'ibm903':
return 'IBM903';
case '904':
case 'cp904':
case 'csibbm904':
case 'ibm904':
return 'IBM904';
case 'cp905':
case 'csibm905':
case 'ebcdiccptr':
case 'ibm905':
return 'IBM905';
case 'cp918':
case 'csibm918':
case 'ebcdiccpar2':
case 'ibm918':
return 'IBM918';
case 'ccsid924':
case 'cp924':
case 'ebcdiclatin9euro':
case 'ibm924':
return 'IBM00924';
case 'cp1026':
case 'csibm1026':
case 'ibm1026':
return 'IBM1026';
case 'ibm1047':
return 'IBM1047';
case 'ccsid1140':
case 'cp1140':
case 'ebcdicus37euro':
case 'ibm1140':
return 'IBM01140';
case 'ccsid1141':
case 'cp1141':
case 'ebcdicde273euro':
case 'ibm1141':
return 'IBM01141';
case 'ccsid1142':
case 'cp1142':
case 'ebcdicdk277euro':
case 'ebcdicno277euro':
case 'ibm1142':
return 'IBM01142';
case 'ccsid1143':
case 'cp1143':
case 'ebcdicfi278euro':
case 'ebcdicse278euro':
case 'ibm1143':
return 'IBM01143';
case 'ccsid1144':
case 'cp1144':
case 'ebcdicit280euro':
case 'ibm1144':
return 'IBM01144';
case 'ccsid1145':
case 'cp1145':
case 'ebcdices284euro':
case 'ibm1145':
return 'IBM01145';
case 'ccsid1146':
case 'cp1146':
case 'ebcdicgb285euro':
case 'ibm1146':
return 'IBM01146';
case 'ccsid1147':
case 'cp1147':
case 'ebcdicfr297euro':
case 'ibm1147':
return 'IBM01147';
case 'ccsid1148':
case 'cp1148':
case 'ebcdicinternational500euro':
case 'ibm1148':
return 'IBM01148';
case 'ccsid1149':
case 'cp1149':
case 'ebcdicis871euro':
case 'ibm1149':
return 'IBM01149';
case 'csiso143iecp271':
case 'iecp271':
case 'isoir143':
return 'IEC_P27-1';
case 'csiso49inis':
case 'inis':
case 'isoir49':
return 'INIS';
case 'csiso50inis8':
case 'inis8':
case 'isoir50':
return 'INIS-8';
case 'csiso51iniscyrillic':
case 'iniscyrillic':
case 'isoir51':
return 'INIS-cyrillic';
case 'csinvariant':
case 'invariant':
return 'INVARIANT';
case 'iso2022cn':
return 'ISO-2022-CN';
case 'iso2022cnext':
return 'ISO-2022-CN-EXT';
case 'csiso2022jp':
case 'iso2022jp':
return 'ISO-2022-JP';
case 'csiso2022jp2':
case 'iso2022jp2':
return 'ISO-2022-JP-2';
case 'csiso2022kr':
case 'iso2022kr':
return 'ISO-2022-KR';
case 'cswindows30latin1':
case 'iso88591windows30latin1':
return 'ISO-8859-1-Windows-3.0-Latin-1';
case 'cswindows31latin1':
case 'iso88591windows31latin1':
return 'ISO-8859-1-Windows-3.1-Latin-1';
case 'csisolatin2':
case 'iso88592':
case 'iso885921987':
case 'isoir101':
case 'l2':
case 'latin2':
return 'ISO-8859-2';
case 'cswindows31latin2':
case 'iso88592windowslatin2':
return 'ISO-8859-2-Windows-Latin-2';
case 'csisolatin3':
case 'iso88593':
case 'iso885931988':
case 'isoir109':
case 'l3':
case 'latin3':
return 'ISO-8859-3';
case 'csisolatin4':
case 'iso88594':
case 'iso885941988':
case 'isoir110':
case 'l4':
case 'latin4':
return 'ISO-8859-4';
case 'csisolatincyrillic':
case 'cyrillic':
case 'iso88595':
case 'iso885951988':
case 'isoir144':
return 'ISO-8859-5';
case 'arabic':
case 'asmo708':
case 'csisolatinarabic':
case 'ecma114':
case 'iso88596':
case 'iso885961987':
case 'isoir127':
return 'ISO-8859-6';
case 'csiso88596e':
case 'iso88596e':
return 'ISO-8859-6-E';
case 'csiso88596i':
case 'iso88596i':
return 'ISO-8859-6-I';
case 'csisolatingreek':
case 'ecma118':
case 'elot928':
case 'greek':
case 'greek8':
case 'iso88597':
case 'iso885971987':
case 'isoir126':
return 'ISO-8859-7';
case 'csisolatinhebrew':
case 'hebrew':
case 'iso88598':
case 'iso885981988':
case 'isoir138':
return 'ISO-8859-8';
case 'csiso88598e':
case 'iso88598e':
return 'ISO-8859-8-E';
case 'csiso88598i':
case 'iso88598i':
return 'ISO-8859-8-I';
case 'cswindows31latin5':
case 'iso88599windowslatin5':
return 'ISO-8859-9-Windows-Latin-5';
case 'csisolatin6':
case 'iso885910':
case 'iso8859101992':
case 'isoir157':
case 'l6':
case 'latin6':
return 'ISO-8859-10';
case 'iso885913':
return 'ISO-8859-13';
case 'iso885914':
case 'iso8859141998':
case 'isoceltic':
case 'isoir199':
case 'l8':
case 'latin8':
return 'ISO-8859-14';
case 'iso885915':
case 'latin9':
return 'ISO-8859-15';
case 'iso885916':
case 'iso8859162001':
case 'isoir226':
case 'l10':
case 'latin10':
return 'ISO-8859-16';
case 'iso10646j1':
return 'ISO-10646-J-1';
case 'csunicode':
case 'iso10646ucs2':
return 'ISO-10646-UCS-2';
case 'csucs4':
case 'iso10646ucs4':
return 'ISO-10646-UCS-4';
case 'csunicodeascii':
case 'iso10646ucsbasic':
return 'ISO-10646-UCS-Basic';
case 'csunicodelatin1':
case 'iso10646':
case 'iso10646unicodelatin1':
return 'ISO-10646-Unicode-Latin1';
case 'csiso10646utf1':
case 'iso10646utf1':
return 'ISO-10646-UTF-1';
case 'csiso115481':
case 'iso115481':
case 'isotr115481':
return 'ISO-11548-1';
case 'csiso90':
case 'isoir90':
return 'iso-ir-90';
case 'csunicodeibm1261':
case 'isounicodeibm1261':
return 'ISO-Unicode-IBM-1261';
case 'csunicodeibm1264':
case 'isounicodeibm1264':
return 'ISO-Unicode-IBM-1264';
case 'csunicodeibm1265':
case 'isounicodeibm1265':
return 'ISO-Unicode-IBM-1265';
case 'csunicodeibm1268':
case 'isounicodeibm1268':
return 'ISO-Unicode-IBM-1268';
case 'csunicodeibm1276':
case 'isounicodeibm1276':
return 'ISO-Unicode-IBM-1276';
case 'csiso646basic1983':
case 'iso646basic1983':
case 'ref':
return 'ISO_646.basic:1983';
case 'csiso2intlrefversion':
case 'irv':
case 'iso646irv1983':
case 'isoir2':
return 'ISO_646.irv:1983';
case 'csiso2033':
case 'e13b':
case 'iso20331983':
case 'isoir98':
return 'ISO_2033-1983';
case 'csiso5427cyrillic':
case 'iso5427':
case 'isoir37':
return 'ISO_5427';
case 'iso5427cyrillic1981':
case 'iso54271981':
case 'isoir54':
return 'ISO_5427:1981';
case 'csiso5428greek':
case 'iso54281980':
case 'isoir55':
return 'ISO_5428:1980';
case 'csiso6937add':
case 'iso6937225':
case 'isoir152':
return 'ISO_6937-2-25';
case 'csisotextcomm':
case 'iso69372add':
case 'isoir142':
return 'ISO_6937-2-add';
case 'csiso8859supp':
case 'iso8859supp':
case 'isoir154':
case 'latin125':
return 'ISO_8859-supp';
case 'csiso10367box':
case 'iso10367box':
case 'isoir155':
return 'ISO_10367-box';
case 'csiso15italian':
case 'iso646it':
case 'isoir15':
case 'it':
return 'IT';
case 'csiso13jisc6220jp':
case 'isoir13':
case 'jisc62201969':
case 'jisc62201969jp':
case 'katakana':
case 'x2017':
return 'JIS_C6220-1969-jp';
case 'csiso14jisc6220ro':
case 'iso646jp':
case 'isoir14':
case 'jisc62201969ro':
case 'jp':
return 'JIS_C6220-1969-ro';
case 'csiso42jisc62261978':
case 'isoir42':
case 'jisc62261978':
return 'JIS_C6226-1978';
case 'csiso87jisx208':
case 'isoir87':
case 'jisc62261983':
case 'jisx2081983':
case 'x208':
return 'JIS_C6226-1983';
case 'csiso91jisc62291984a':
case 'isoir91':
case 'jisc62291984a':
case 'jpocra':
return 'JIS_C6229-1984-a';
case 'csiso92jisc62991984b':
case 'iso646jpocrb':
case 'isoir92':
case 'jisc62291984b':
case 'jpocrb':
return 'JIS_C6229-1984-b';
case 'csiso93jis62291984badd':
case 'isoir93':
case 'jisc62291984badd':
case 'jpocrbadd':
return 'JIS_C6229-1984-b-add';
case 'csiso94jis62291984hand':
case 'isoir94':
case 'jisc62291984hand':
case 'jpocrhand':
return 'JIS_C6229-1984-hand';
case 'csiso95jis62291984handadd':
case 'isoir95':
case 'jisc62291984handadd':
case 'jpocrhandadd':
return 'JIS_C6229-1984-hand-add';
case 'csiso96jisc62291984kana':
case 'isoir96':
case 'jisc62291984kana':
return 'JIS_C6229-1984-kana';
case 'csjisencoding':
case 'jisencoding':
return 'JIS_Encoding';
case 'cshalfwidthkatakana':
case 'jisx201':
case 'x201':
return 'JIS_X0201';
case 'csiso159jisx2121990':
case 'isoir159':
case 'jisx2121990':
case 'x212':
return 'JIS_X0212-1990';
case 'csiso141jusib1002':
case 'iso646yu':
case 'isoir141':
case 'js':
case 'jusib1002':
case 'yu':
return 'JUS_I.B1.002';
case 'csiso147macedonian':
case 'isoir147':
case 'jusib1003mac':
case 'macedonian':
return 'JUS_I.B1.003-mac';
case 'csiso146serbian':
case 'isoir146':
case 'jusib1003serb':
case 'serbian':
return 'JUS_I.B1.003-serb';
case 'koi7switched':
return 'KOI7-switched';
case 'cskoi8r':
case 'koi8r':
return 'KOI8-R';
case 'koi8u':
return 'KOI8-U';
case 'csksc5636':
case 'iso646kr':
case 'ksc5636':
return 'KSC5636';
case 'cskz1048':
case 'kz1048':
case 'rk1048':
case 'strk10482002':
return 'KZ-1048';
case 'csiso19latingreek':
case 'isoir19':
case 'latingreek':
return 'latin-greek';
case 'csiso27latingreek1':
case 'isoir27':
case 'latingreek1':
return 'Latin-greek-1';
case 'csiso158lap':
case 'isoir158':
case 'lap':
case 'latinlap':
return 'latin-lap';
case 'csmacintosh':
case 'mac':
case 'macintosh':
return 'macintosh';
case 'csmicrosoftpublishing':
case 'microsoftpublishing':
return 'Microsoft-Publishing';
case 'csmnem':
case 'mnem':
return 'MNEM';
case 'csmnemonic':
case 'mnemonic':
return 'MNEMONIC';
case 'csiso86hungarian':
case 'hu':
case 'iso646hu':
case 'isoir86':
case 'msz77953':
return 'MSZ_7795.3';
case 'csnatsdano':
case 'isoir91':
case 'natsdano':
return 'NATS-DANO';
case 'csnatsdanoadd':
case 'isoir92':
case 'natsdanoadd':
return 'NATS-DANO-ADD';
case 'csnatssefi':
case 'isoir81':
case 'natssefi':
return 'NATS-SEFI';
case 'csnatssefiadd':
case 'isoir82':
case 'natssefiadd':
return 'NATS-SEFI-ADD';
case 'csiso151cuba':
case 'cuba':
case 'iso646cu':
case 'isoir151':
case 'ncnc1081':
return 'NC_NC00-10:81';
case 'csiso69french':
case 'fr':
case 'iso646fr':
case 'isoir69':
case 'nfz62010':
return 'NF_Z_62-010';
case 'csiso25french':
case 'iso646fr1':
case 'isoir25':
case 'nfz620101973':
return 'NF_Z_62-010_(1973)';
case 'csiso60danishnorwegian':
case 'csiso60norwegian1':
case 'iso646no':
case 'isoir60':
case 'no':
case 'ns45511':
return 'NS_4551-1';
case 'csiso61norwegian2':
case 'iso646no2':
case 'isoir61':
case 'no2':
case 'ns45512':
return 'NS_4551-2';
case 'osdebcdicdf3irv':
return 'OSD_EBCDIC_DF03_IRV';
case 'osdebcdicdf41':
return 'OSD_EBCDIC_DF04_1';
case 'osdebcdicdf415':
return 'OSD_EBCDIC_DF04_15';
case 'cspc8danishnorwegian':
case 'pc8danishnorwegian':
return 'PC8-Danish-Norwegian';
case 'cspc8turkish':
case 'pc8turkish':
return 'PC8-Turkish';
case 'csiso16portuguese':
case 'iso646pt':
case 'isoir16':
case 'pt':
return 'PT';
case 'csiso84portuguese2':
case 'iso646pt2':
case 'isoir84':
case 'pt2':
return 'PT2';
case 'cp154':
case 'csptcp154':
case 'cyrillicasian':
case 'pt154':
case 'ptcp154':
return 'PTCP154';
case 'scsu':
return 'SCSU';
case 'csiso10swedish':
case 'fi':
case 'iso646fi':
case 'iso646se':
case 'isoir10':
case 'se':
case 'sen850200b':
return 'SEN_850200_B';
case 'csiso11swedishfornames':
case 'iso646se2':
case 'isoir11':
case 'se2':
case 'sen850200c':
return 'SEN_850200_C';
case 'csiso102t617bit':
case 'isoir102':
case 't617bit':
return 'T.61-7bit';
case 'csiso103t618bit':
case 'isoir103':
case 't61':
case 't618bit':
return 'T.61-8bit';
case 'csiso128t101g2':
case 'isoir128':
case 't101g2':
return 'T.101-G2';
case 'cstscii':
case 'tscii':
return 'TSCII';
case 'csunicode11':
case 'unicode11':
return 'UNICODE-1-1';
case 'csunicode11utf7':
case 'unicode11utf7':
return 'UNICODE-1-1-UTF-7';
case 'csunknown8bit':
case 'unknown8bit':
return 'UNKNOWN-8BIT';
case 'ansix341968':
case 'ansix341986':
case 'ascii':
case 'cp367':
case 'csascii':
case 'ibm367':
case 'iso646irv1991':
case 'iso646us':
case 'isoir6':
case 'us':
case 'usascii':
return 'US-ASCII';
case 'csusdk':
case 'usdk':
return 'us-dk';
case 'utf7':
return 'UTF-7';
case 'utf8':
return 'UTF-8';
case 'utf16':
return 'UTF-16';
case 'utf16be':
return 'UTF-16BE';
case 'utf16le':
return 'UTF-16LE';
case 'utf32':
return 'UTF-32';
case 'utf32be':
return 'UTF-32BE';
case 'utf32le':
return 'UTF-32LE';
case 'csventurainternational':
case 'venturainternational':
return 'Ventura-International';
case 'csventuramath':
case 'venturamath':
return 'Ventura-Math';
case 'csventuraus':
case 'venturaus':
return 'Ventura-US';
case 'csiso70videotexsupp1':
case 'isoir70':
case 'videotexsuppl':
return 'videotex-suppl';
case 'csviqr':
case 'viqr':
return 'VIQR';
case 'csviscii':
case 'viscii':
return 'VISCII';
case 'csshiftjis':
case 'cswindows31j':
case 'mskanji':
case 'shiftjis':
case 'windows31j':
return 'Windows-31J';
case 'iso885911':
case 'tis620':
return 'windows-874';
case 'cseuckr':
case 'csksc56011987':
case 'euckr':
case 'isoir149':
case 'korean':
case 'ksc5601':
case 'ksc56011987':
case 'ksc56011989':
case 'windows949':
return 'windows-949';
case 'windows1250':
return 'windows-1250';
case 'windows1251':
return 'windows-1251';
case 'cp819':
case 'csisolatin1':
case 'ibm819':
case 'iso88591':
case 'iso885911987':
case 'isoir100':
case 'l1':
case 'latin1':
case 'windows1252':
return 'windows-1252';
case 'windows1253':
return 'windows-1253';
case 'csisolatin5':
case 'iso88599':
case 'iso885991989':
case 'isoir148':
case 'l5':
case 'latin5':
case 'windows1254':
return 'windows-1254';
case 'windows1255':
return 'windows-1255';
case 'windows1256':
return 'windows-1256';
case 'windows1257':
return 'windows-1257';
case 'windows1258':
return 'windows-1258';
default:
return $charset;
}
}
/**
* @return string
*/
public static function get_curl_version()
{
if (is_array($curl = curl_version())) {
$curl = $curl['version'];
} else {
$curl = '0';
}
return $curl;
}
/**
* Strip HTML comments
*
* @deprecated since SimplePie 1.9.0. If you need it, you can copy the function to your codebase. But you should consider using `DOMDocument` for any DOM wrangling.
* @param string $data Data to strip comments from
* @return string Comment stripped string
*/
public static function strip_comments(string $data)
{
// trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.9.'), \E_USER_DEPRECATED);
$output = '';
while (($start = strpos($data, '', $start)) !== false) {
$data = substr_replace($data, '', 0, $end + 3);
} else {
$data = '';
}
}
return $output . $data;
}
/**
* @return int|false
*/
public static function parse_date(string $dt)
{
$parser = \SimplePie\Parse\Date::get();
return $parser->parse($dt);
}
/**
* Decode HTML entities
*
* @deprecated since SimplePie 1.3, use DOMDocument instead
* @param string $data Input data
* @return string Output data
*/
public static function entities_decode(string $data)
{
// trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.3, use "DOMDocument" instead.'), \E_USER_DEPRECATED);
$decoder = new \SimplePie_Decode_HTML_Entities($data);
return $decoder->parse();
}
/**
* Remove RFC822 comments
*
* @deprecated since SimplePie 1.9.0. If you need it, consider copying the function to your codebase.
* @param string $string Data to strip comments from
* @return string Comment stripped string
*/
public static function uncomment_rfc822(string $string)
{
// trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.9.'), \E_USER_DEPRECATED);
$position = 0;
$length = strlen($string);
$depth = 0;
$output = '';
while ($position < $length && ($pos = strpos($string, '(', $position)) !== false) {
$output .= substr($string, $position, $pos - $position);
$position = $pos + 1;
if ($string[$pos - 1] !== '\\') {
$depth++;
while ($depth && $position < $length) {
$position += strcspn($string, '()', $position);
if ($string[$position - 1] === '\\') {
$position++;
continue;
} elseif (isset($string[$position])) {
switch ($string[$position]) {
case '(':
$depth++;
break;
case ')':
$depth--;
break;
}
$position++;
} else {
break;
}
}
} else {
$output .= '(';
}
}
$output .= substr($string, $position);
return $output;
}
/**
* @return string
*/
public static function parse_mime(string $mime)
{
if (($pos = strpos($mime, ';')) === false) {
return trim($mime);
}
return trim(substr($mime, 0, $pos));
}
/**
* @param array> $attribs
* @return int-mask-of
*/
public static function atom_03_construct_type(array $attribs)
{
if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode'])) === 'base64') {
$mode = \SimplePie\SimplePie::CONSTRUCT_BASE64;
} else {
$mode = \SimplePie\SimplePie::CONSTRUCT_NONE;
}
if (isset($attribs['']['type'])) {
switch (strtolower(trim($attribs['']['type']))) {
case 'text':
case 'text/plain':
return \SimplePie\SimplePie::CONSTRUCT_TEXT | $mode;
case 'html':
case 'text/html':
return \SimplePie\SimplePie::CONSTRUCT_HTML | $mode;
case 'xhtml':
case 'application/xhtml+xml':
return \SimplePie\SimplePie::CONSTRUCT_XHTML | $mode;
default:
return \SimplePie\SimplePie::CONSTRUCT_NONE | $mode;
}
}
return \SimplePie\SimplePie::CONSTRUCT_TEXT | $mode;
}
/**
* @param array> $attribs
* @return int-mask-of
*/
public static function atom_10_construct_type(array $attribs)
{
if (isset($attribs['']['type'])) {
switch (strtolower(trim($attribs['']['type']))) {
case 'text':
return \SimplePie\SimplePie::CONSTRUCT_TEXT;
case 'html':
return \SimplePie\SimplePie::CONSTRUCT_HTML;
case 'xhtml':
return \SimplePie\SimplePie::CONSTRUCT_XHTML;
default:
return \SimplePie\SimplePie::CONSTRUCT_NONE;
}
}
return \SimplePie\SimplePie::CONSTRUCT_TEXT;
}
/**
* @param array> $attribs
* @return int-mask-of
*/
public static function atom_10_content_construct_type(array $attribs)
{
if (isset($attribs['']['type'])) {
$type = strtolower(trim($attribs['']['type']));
switch ($type) {
case 'text':
return \SimplePie\SimplePie::CONSTRUCT_TEXT;
case 'html':
return \SimplePie\SimplePie::CONSTRUCT_HTML;
case 'xhtml':
return \SimplePie\SimplePie::CONSTRUCT_XHTML;
}
if (in_array(substr($type, -4), ['+xml', '/xml']) || substr($type, 0, 5) === 'text/') {
return \SimplePie\SimplePie::CONSTRUCT_NONE;
} else {
return \SimplePie\SimplePie::CONSTRUCT_BASE64;
}
}
return \SimplePie\SimplePie::CONSTRUCT_TEXT;
}
/**
* @return bool
*/
public static function is_isegment_nz_nc(string $string)
{
return (bool) preg_match('/^([A-Za-z0-9\-._~\x{A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}\x{10000}-\x{1FFFD}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}\x{40000}-\x{4FFFD}\x{50000}-\x{5FFFD}\x{60000}-\x{6FFFD}\x{70000}-\x{7FFFD}\x{80000}-\x{8FFFD}\x{90000}-\x{9FFFD}\x{A0000}-\x{AFFFD}\x{B0000}-\x{BFFFD}\x{C0000}-\x{CFFFD}\x{D0000}-\x{DFFFD}\x{E1000}-\x{EFFFD}!$&\'()*+,;=@]|(%[0-9ABCDEF]{2}))+$/u', $string);
}
/**
* @return string[]
*/
public static function space_separated_tokens(string $string)
{
$space_characters = "\x20\x09\x0A\x0B\x0C\x0D";
$string_length = strlen($string);
$position = strspn($string, $space_characters);
$tokens = [];
while ($position < $string_length) {
$len = strcspn($string, $space_characters, $position);
$tokens[] = substr($string, $position, $len);
$position += $len;
$position += strspn($string, $space_characters, $position);
}
return $tokens;
}
/**
* Converts a unicode codepoint to a UTF-8 character
*
* @static
* @param int $codepoint Unicode codepoint
* @return string|false UTF-8 character
*/
public static function codepoint_to_utf8(int $codepoint)
{
if ($codepoint < 0) {
return false;
} elseif ($codepoint <= 0x7f) {
return chr($codepoint);
} elseif ($codepoint <= 0x7ff) {
return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
} elseif ($codepoint <= 0xffff) {
return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
} elseif ($codepoint <= 0x10ffff) {
return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
}
// U+FFFD REPLACEMENT CHARACTER
return "\xEF\xBF\xBD";
}
/**
* Similar to parse_str()
*
* Returns an associative array of name/value pairs, where the value is an
* array of values that have used the same name
*
* @deprecated since SimplePie 1.9.0. If you need it, consider copying the function to your codebase.
* @static
* @param string $str The input string.
* @return array>
*/
public static function parse_str(string $str)
{
// trigger_error(sprintf('Using method "' . __METHOD__ . '" is deprecated since SimplePie 1.9.'), \E_USER_DEPRECATED);
$return = [];
$str = explode('&', $str);
foreach ($str as $section) {
if (strpos($section, '=') !== false) {
[$name, $value] = explode('=', $section, 2);
$return[urldecode($name)][] = urldecode($value);
} else {
$return[urldecode($section)][] = null;
}
}
return $return;
}
/**
* Detect XML encoding, as per XML 1.0 Appendix F.1
*
* @todo Add support for EBCDIC
* @param string $data XML data
* @param \SimplePie\Registry $registry Class registry
* @return array Possible encodings
*/
public static function xml_encoding(string $data, \SimplePie\Registry $registry)
{
// UTF-32 Big Endian BOM
if (substr($data, 0, 4) === "\x00\x00\xFE\xFF") {
$encoding[] = 'UTF-32BE';
}
// UTF-32 Little Endian BOM
elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00") {
$encoding[] = 'UTF-32LE';
}
// UTF-16 Big Endian BOM
elseif (substr($data, 0, 2) === "\xFE\xFF") {
$encoding[] = 'UTF-16BE';
}
// UTF-16 Little Endian BOM
elseif (substr($data, 0, 2) === "\xFF\xFE") {
$encoding[] = 'UTF-16LE';
}
// UTF-8 BOM
elseif (substr($data, 0, 3) === "\xEF\xBB\xBF") {
$encoding[] = 'UTF-8';
}
// UTF-32 Big Endian Without BOM
elseif (substr($data, 0, 20) === "\x00\x00\x00\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C") {
if ($pos = strpos($data, "\x00\x00\x00\x3F\x00\x00\x00\x3E")) {
$parser = $registry->create(Parser::class, [Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32BE', 'UTF-8')]);
if ($parser->parse()) {
$encoding[] = $parser->encoding;
}
}
$encoding[] = 'UTF-32BE';
}
// UTF-32 Little Endian Without BOM
elseif (substr($data, 0, 20) === "\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C\x00\x00\x00") {
if ($pos = strpos($data, "\x3F\x00\x00\x00\x3E\x00\x00\x00")) {
$parser = $registry->create(Parser::class, [Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32LE', 'UTF-8')]);
if ($parser->parse()) {
$encoding[] = $parser->encoding;
}
}
$encoding[] = 'UTF-32LE';
}
// UTF-16 Big Endian Without BOM
elseif (substr($data, 0, 10) === "\x00\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C") {
if ($pos = strpos($data, "\x00\x3F\x00\x3E")) {
$parser = $registry->create(Parser::class, [Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16BE', 'UTF-8')]);
if ($parser->parse()) {
$encoding[] = $parser->encoding;
}
}
$encoding[] = 'UTF-16BE';
}
// UTF-16 Little Endian Without BOM
elseif (substr($data, 0, 10) === "\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C\x00") {
if ($pos = strpos($data, "\x3F\x00\x3E\x00")) {
$parser = $registry->create(Parser::class, [Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16LE', 'UTF-8')]);
if ($parser->parse()) {
$encoding[] = $parser->encoding;
}
}
$encoding[] = 'UTF-16LE';
}
// US-ASCII (or superset)
elseif (substr($data, 0, 5) === "\x3C\x3F\x78\x6D\x6C") {
if ($pos = strpos($data, "\x3F\x3E")) {
$parser = $registry->create(Parser::class, [substr($data, 5, $pos - 5)]);
if ($parser->parse()) {
$encoding[] = $parser->encoding;
}
}
$encoding[] = 'UTF-8';
}
// Fallback to UTF-8
else {
$encoding[] = 'UTF-8';
}
return $encoding;
}
/**
* @return void
*/
public static function output_javascript()
{
if (function_exists('ob_gzhandler')) {
ob_start('ob_gzhandler');
}
header('Content-type: text/javascript; charset: UTF-8');
header('Cache-Control: must-revalidate');
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 604800) . ' GMT'); // 7 days
$body = <<');
}
else {
document.writeln('');
}
}
function embed_flash(bgcolor, width, height, link, loop, type) {
document.writeln('');
}
function embed_flv(width, height, link, placeholder, loop, player) {
document.writeln('');
}
function embed_wmedia(width, height, link) {
document.writeln('');
}
JS;
echo $body;
}
/**
* Get the SimplePie build timestamp
*
* Uses the git index if it exists, otherwise uses the modification time
* of the newest file.
*
* @return int
*/
public static function get_build()
{
if (self::$SIMPLEPIE_BUILD !== null) {
return self::$SIMPLEPIE_BUILD;
}
$root = dirname(__FILE__, 2);
if (file_exists($root . '/.git/index')) {
self::$SIMPLEPIE_BUILD = (int) filemtime($root . '/.git/index');
return self::$SIMPLEPIE_BUILD;
} elseif (file_exists($root . '/src')) {
$time = 0;
foreach (glob($root . '/src/*.php') ?: [] as $file) {
if (($mtime = filemtime($file)) > $time) {
$time = $mtime;
}
}
self::$SIMPLEPIE_BUILD = $time;
return self::$SIMPLEPIE_BUILD;
}
self::$SIMPLEPIE_BUILD = (int) filemtime(__FILE__);
return self::$SIMPLEPIE_BUILD;
}
/**
* Get the default user agent string
*
* @return string
*/
public static function get_default_useragent()
{
return \SimplePie\SimplePie::NAME . '/' . \SimplePie\SimplePie::VERSION . ' (Feed Parser; ' . \SimplePie\SimplePie::URL . '; Allow like Gecko) Build/' . static::get_build();
}
/**
* Format debugging information
*
* @return string
*/
public static function debug(SimplePie &$sp)
{
$info = 'SimplePie ' . \SimplePie\SimplePie::VERSION . ' Build ' . static::get_build() . "\n";
$info .= 'PHP ' . PHP_VERSION . "\n";
if ($sp->error() !== null) {
// TODO: Remove cast with multifeeds.
$info .= 'Error occurred: ' . implode(', ', (array) $sp->error()) . "\n";
} else {
$info .= "No error found.\n";
}
$info .= "Extensions:\n";
$extensions = ['pcre', 'curl', 'zlib', 'mbstring', 'iconv', 'xmlreader', 'xml'];
foreach ($extensions as $ext) {
if (extension_loaded($ext)) {
$info .= " $ext loaded\n";
switch ($ext) {
case 'pcre':
$info .= ' Version ' . PCRE_VERSION . "\n";
break;
case 'curl':
$version = (array) curl_version();
$info .= ' Version ' . $version['version'] . "\n";
break;
case 'iconv':
$info .= ' Version ' . ICONV_VERSION . "\n";
break;
case 'xml':
$info .= ' Version ' . LIBXML_DOTTED_VERSION . "\n";
break;
}
} else {
$info .= " $ext not loaded\n";
}
}
return $info;
}
/**
* @return bool
*/
public static function silence_errors(int $num, string $str)
{
// No-op
return true;
}
/**
* Sanitize a URL by removing HTTP credentials.
* @param string $url the URL to sanitize.
* @return string the same URL without HTTP credentials.
*/
public static function url_remove_credentials(string $url)
{
// Cast for PHPStan: I do not think this can fail.
// The regex is valid and there should be no backtracking.
// https://github.com/phpstan/phpstan/issues/11547
return (string) preg_replace('#^(https?://)[^/:@]+:[^/:@]+@#i', '$1', $url);
}
}
class_alias('SimplePie\Misc', 'SimplePie_Misc', false);
src/File.php 0000644 00000045702 15143517255 0006743 0 ustar 00 > Canonical representation of headers */
private $parsed_headers = [];
/** @var array Last known value of $headers property (used to detect external modification) */
private $last_headers = [];
/**
* @var array Headers as string for BC
* @deprecated Use `get_headers()` method.
*/
public $headers = [];
/**
* @var ?string Body of the HTTP response
* @deprecated Use `get_body_content()` method.
*/
public $body;
/**
* @var int Status code of the HTTP response
* @deprecated Use `get_status_code()` method.
*/
public $status_code = 0;
/** @var non-negative-int Number of redirect that were already performed during this request sequence. */
public $redirects = 0;
/** @var ?string */
public $error;
/**
* @var int-mask-of Bit mask representing the method used to fetch the file and whether it is a local file or remote file obtained over HTTP.
* @deprecated Backend is implementation detail which you should not care about; to see if the file was retrieved over HTTP, check if `get_final_requested_uri()` with `Misc::is_remote_uri()`.
*/
public $method = \SimplePie\SimplePie::FILE_SOURCE_NONE;
/**
* @var string The permanent URL or the resource (first URL after the prefix of (only) permanent redirects)
* @deprecated Use `get_permanent_uri()` method.
*/
public $permanent_url;
/** @var bool Whether the permanent URL is still writeable (prefix of permanent redirects has not ended) */
private $permanentUrlMutable = true;
/**
* @param string $url
* @param int $timeout
* @param int $redirects
* @param ?array $headers
* @param ?string $useragent
* @param bool $force_fsockopen
* @param array $curl_options
*/
public function __construct(string $url, int $timeout = 10, int $redirects = 5, ?array $headers = null, ?string $useragent = null, bool $force_fsockopen = false, array $curl_options = [])
{
if (function_exists('idn_to_ascii')) {
$parsed = \SimplePie\Misc::parse_url($url);
if ($parsed['authority'] !== '' && !ctype_print($parsed['authority'])) {
$authority = (string) \idn_to_ascii($parsed['authority'], \IDNA_NONTRANSITIONAL_TO_ASCII, \INTL_IDNA_VARIANT_UTS46);
$url = \SimplePie\Misc::compress_parse_url($parsed['scheme'], $authority, $parsed['path'], $parsed['query'], null);
}
}
$this->url = $url;
if ($this->permanentUrlMutable) {
$this->permanent_url = $url;
}
$this->useragent = $useragent;
if (preg_match('/^http(s)?:\/\//i', $url)) {
if ($useragent === null) {
$useragent = (string) ini_get('user_agent');
$this->useragent = $useragent;
}
if (!is_array($headers)) {
$headers = [];
}
if (!$force_fsockopen && function_exists('curl_exec')) {
$this->method = \SimplePie\SimplePie::FILE_SOURCE_REMOTE | \SimplePie\SimplePie::FILE_SOURCE_CURL;
$fp = curl_init();
$headers2 = [];
foreach ($headers as $key => $value) {
$headers2[] = "$key: $value";
}
if (isset($curl_options[CURLOPT_HTTPHEADER])) {
if (is_array($curl_options[CURLOPT_HTTPHEADER])) {
$headers2 = array_merge($headers2, $curl_options[CURLOPT_HTTPHEADER]);
}
unset($curl_options[CURLOPT_HTTPHEADER]);
}
if (version_compare(\SimplePie\Misc::get_curl_version(), '7.10.5', '>=')) {
curl_setopt($fp, CURLOPT_ENCODING, '');
}
curl_setopt($fp, CURLOPT_URL, $url);
curl_setopt($fp, CURLOPT_HEADER, 1);
curl_setopt($fp, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($fp, CURLOPT_FAILONERROR, 1);
curl_setopt($fp, CURLOPT_TIMEOUT, $timeout);
curl_setopt($fp, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($fp, CURLOPT_REFERER, \SimplePie\Misc::url_remove_credentials($url));
curl_setopt($fp, CURLOPT_USERAGENT, $useragent);
curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2);
foreach ($curl_options as $curl_param => $curl_value) {
curl_setopt($fp, $curl_param, $curl_value);
}
$responseHeaders = curl_exec($fp);
if (curl_errno($fp) === CURLE_WRITE_ERROR || curl_errno($fp) === CURLE_BAD_CONTENT_ENCODING) {
curl_setopt($fp, CURLOPT_ENCODING, 'none');
$responseHeaders = curl_exec($fp);
}
$this->status_code = curl_getinfo($fp, CURLINFO_HTTP_CODE);
if (curl_errno($fp)) {
$this->error = 'cURL error ' . curl_errno($fp) . ': ' . curl_error($fp);
$this->success = false;
} else {
// Use the updated url provided by curl_getinfo after any redirects.
if ($info = curl_getinfo($fp)) {
$this->url = $info['url'];
}
// For PHPStan: We already checked that error did not occur.
assert(is_array($info) && $info['redirect_count'] >= 0);
if (\PHP_VERSION_ID < 80000) {
curl_close($fp);
}
$responseHeaders = \SimplePie\HTTP\Parser::prepareHeaders((string) $responseHeaders, $info['redirect_count'] + 1);
$parser = new \SimplePie\HTTP\Parser($responseHeaders, true);
if ($parser->parse()) {
$this->set_headers($parser->headers);
$this->body = $parser->body;
$this->status_code = $parser->status_code;
if ((in_array($this->status_code, [300, 301, 302, 303, 307]) || $this->status_code > 307 && $this->status_code < 400) && ($locationHeader = $this->get_header_line('location')) !== '' && $this->redirects < $redirects) {
$this->redirects++;
$location = \SimplePie\Misc::absolutize_url($locationHeader, $url);
if ($location === false) {
$this->error = "Invalid redirect location, trying to base “{$locationHeader}” onto “{$url}”";
$this->success = false;
return;
}
$this->permanentUrlMutable = $this->permanentUrlMutable && ($this->status_code == 301 || $this->status_code == 308);
$this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen, $curl_options);
return;
}
}
}
} else {
$this->method = \SimplePie\SimplePie::FILE_SOURCE_REMOTE | \SimplePie\SimplePie::FILE_SOURCE_FSOCKOPEN;
if (($url_parts = parse_url($url)) === false) {
throw new \InvalidArgumentException('Malformed URL: ' . $url);
}
if (!isset($url_parts['host'])) {
throw new \InvalidArgumentException('Missing hostname: ' . $url);
}
$socket_host = $url_parts['host'];
if (isset($url_parts['scheme']) && strtolower($url_parts['scheme']) === 'https') {
$socket_host = 'ssl://' . $socket_host;
$url_parts['port'] = 443;
}
if (!isset($url_parts['port'])) {
$url_parts['port'] = 80;
}
$fp = @fsockopen($socket_host, $url_parts['port'], $errno, $errstr, $timeout);
if (!$fp) {
$this->error = 'fsockopen error: ' . $errstr;
$this->success = false;
} else {
stream_set_timeout($fp, $timeout);
if (isset($url_parts['path'])) {
if (isset($url_parts['query'])) {
$get = "$url_parts[path]?$url_parts[query]";
} else {
$get = $url_parts['path'];
}
} else {
$get = '/';
}
$out = "GET $get HTTP/1.1\r\n";
$out .= "Host: $url_parts[host]\r\n";
$out .= "User-Agent: $useragent\r\n";
if (extension_loaded('zlib')) {
$out .= "Accept-Encoding: x-gzip,gzip,deflate\r\n";
}
if (isset($url_parts['user']) && isset($url_parts['pass'])) {
$out .= "Authorization: Basic " . base64_encode("$url_parts[user]:$url_parts[pass]") . "\r\n";
}
foreach ($headers as $key => $value) {
$out .= "$key: $value\r\n";
}
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
$info = stream_get_meta_data($fp);
$responseHeaders = '';
while (!$info['eof'] && !$info['timed_out']) {
$responseHeaders .= fread($fp, 1160);
$info = stream_get_meta_data($fp);
}
if (!$info['timed_out']) {
$parser = new \SimplePie\HTTP\Parser($responseHeaders, true);
if ($parser->parse()) {
$this->set_headers($parser->headers);
$this->body = $parser->body;
$this->status_code = $parser->status_code;
if ((in_array($this->status_code, [300, 301, 302, 303, 307]) || $this->status_code > 307 && $this->status_code < 400) && ($locationHeader = $this->get_header_line('location')) !== '' && $this->redirects < $redirects) {
$this->redirects++;
$location = \SimplePie\Misc::absolutize_url($locationHeader, $url);
$this->permanentUrlMutable = $this->permanentUrlMutable && ($this->status_code == 301 || $this->status_code == 308);
if ($location === false) {
$this->error = "Invalid redirect location, trying to base “{$locationHeader}” onto “{$url}”";
$this->success = false;
return;
}
$this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen, $curl_options);
return;
}
if (($contentEncodingHeader = $this->get_header_line('content-encoding')) !== '') {
// Hey, we act dumb elsewhere, so let's do that here too
switch (strtolower(trim($contentEncodingHeader, "\x09\x0A\x0D\x20"))) {
case 'gzip':
case 'x-gzip':
if (($decompressed = gzdecode($this->body)) === false) {
$this->error = 'Unable to decode HTTP "gzip" stream';
$this->success = false;
} else {
$this->body = $decompressed;
}
break;
case 'deflate':
if (($decompressed = gzinflate($this->body)) !== false) {
$this->body = $decompressed;
} elseif (($decompressed = gzuncompress($this->body)) !== false) {
$this->body = $decompressed;
} elseif (($decompressed = gzdecode($this->body)) !== false) {
$this->body = $decompressed;
} else {
$this->error = 'Unable to decode HTTP "deflate" stream';
$this->success = false;
}
break;
default:
$this->error = 'Unknown content coding';
$this->success = false;
}
}
}
} else {
$this->error = 'fsocket timed out';
$this->success = false;
}
fclose($fp);
}
}
} else {
$this->method = \SimplePie\SimplePie::FILE_SOURCE_LOCAL | \SimplePie\SimplePie::FILE_SOURCE_FILE_GET_CONTENTS;
if (empty($url) || !is_readable($url) || false === $filebody = file_get_contents($url)) {
$this->body = '';
$this->error = sprintf('file "%s" is not readable', $url);
$this->success = false;
} else {
$this->body = $filebody;
$this->status_code = 200;
}
}
if ($this->success) {
assert($this->body !== null); // For PHPStan
// Leading whitespace may cause XML parsing errors (XML declaration cannot be preceded by anything other than BOM) so we trim it.
// Note that unlike built-in `trim` function’s default settings, we do not trim `\x00` to avoid breaking characters in UTF-16 or UTF-32 encoded strings.
// We also only do that when the whitespace is followed by `<`, so that we do not break e.g. UTF-16LE encoded whitespace like `\n\x00` in half.
$this->body = preg_replace('/^[ \n\r\t\v]+', '<', $this->body);
}
}
public function get_permanent_uri(): string
{
return (string) $this->permanent_url;
}
public function get_final_requested_uri(): string
{
return (string) $this->url;
}
public function get_status_code(): int
{
return (int) $this->status_code;
}
public function get_headers(): array
{
$this->maybe_update_headers();
return $this->parsed_headers;
}
public function has_header(string $name): bool
{
$this->maybe_update_headers();
return $this->get_header($name) !== [];
}
public function get_header(string $name): array
{
$this->maybe_update_headers();
return $this->parsed_headers[strtolower($name)] ?? [];
}
public function with_header(string $name, $value)
{
$this->maybe_update_headers();
$new = clone $this;
$newHeader = [
strtolower($name) => (array) $value,
];
$new->set_headers($newHeader + $this->get_headers());
return $new;
}
public function get_header_line(string $name): string
{
$this->maybe_update_headers();
return implode(', ', $this->get_header($name));
}
public function get_body_content(): string
{
return (string) $this->body;
}
/**
* Check if the $headers property was changed and update the internal state accordingly.
*/
private function maybe_update_headers(): void
{
if ($this->headers !== $this->last_headers) {
$this->parsed_headers = array_map(
function (string $header_line): array {
if (strpos($header_line, ',') === false) {
return [$header_line];
} else {
return array_map('trim', explode(',', $header_line));
}
},
$this->headers
);
}
$this->last_headers = $this->headers;
}
/**
* Sets headers internally.
*
* @param array> $headers
*/
private function set_headers(array $headers): void
{
$this->parsed_headers = $headers;
$this->headers = self::flatten_headers($headers);
$this->last_headers = $this->headers;
}
/**
* Converts PSR-7 compatible headers into a legacy format.
*
* @param array> $headers
*
* @return array
*/
private function flatten_headers(array $headers): array
{
return array_map(function (array $values): string {
return implode(',', $values);
}, $headers);
}
/**
* Create a File instance from another Response
*
* For BC reasons in some places there MUST be a `File` instance
* instead of a `Response` implementation
*
* @see Locator::__construct()
* @internal
*/
final public static function fromResponse(Response $response): self
{
$headers = [];
foreach ($response->get_headers() as $name => $header) {
$headers[$name] = implode(', ', $header);
}
/** @var File */
$file = (new \ReflectionClass(File::class))->newInstanceWithoutConstructor();
$file->url = $response->get_final_requested_uri();
$file->useragent = null;
$file->headers = $headers;
$file->body = $response->get_body_content();
$file->status_code = $response->get_status_code();
$file->permanent_url = $response->get_permanent_uri();
return $file;
}
}
class_alias('SimplePie\File', 'SimplePie_File');
src/Enclosure.php 0000644 00000076616 15143517255 0010033 0 ustar 00 bitrate = $bitrate;
$this->captions = $captions;
$this->categories = $categories;
$this->channels = $channels;
$this->copyright = $copyright;
$this->credits = $credits;
$this->description = $description;
$this->duration = $duration;
$this->expression = $expression;
$this->framerate = $framerate;
$this->hashes = $hashes;
$this->height = $height;
$this->keywords = $keywords;
$this->lang = $lang;
$this->length = $length;
$this->link = $link;
$this->medium = $medium;
$this->player = $player;
$this->ratings = $ratings;
$this->restrictions = $restrictions;
$this->samplingrate = $samplingrate;
$this->thumbnails = $thumbnails;
$this->title = $title;
$this->type = $type;
$this->width = $width;
if (function_exists('idn_to_ascii')) {
$parsed = \SimplePie\Misc::parse_url($link ?? '');
if ($parsed['authority'] !== '' && !ctype_print($parsed['authority'])) {
$authority = (string) \idn_to_ascii($parsed['authority'], \IDNA_NONTRANSITIONAL_TO_ASCII, \INTL_IDNA_VARIANT_UTS46);
$this->link = \SimplePie\Misc::compress_parse_url($parsed['scheme'], $authority, $parsed['path'], $parsed['query'], $parsed['fragment']);
}
}
$this->handler = $this->get_handler(); // Needs to load last
}
/**
* String-ified version
*
* @return string
*/
public function __toString()
{
// There is no $this->data here
return md5(serialize($this));
}
/**
* Get the bitrate
*
* @return string|null
*/
public function get_bitrate()
{
if ($this->bitrate !== null) {
return $this->bitrate;
}
return null;
}
/**
* Get a single caption
*
* @param int $key
* @return \SimplePie\Caption|null
*/
public function get_caption(int $key = 0)
{
$captions = $this->get_captions();
if (isset($captions[$key])) {
return $captions[$key];
}
return null;
}
/**
* Get all captions
*
* @return Caption[]|null
*/
public function get_captions()
{
if ($this->captions !== null) {
return $this->captions;
}
return null;
}
/**
* Get a single category
*
* @param int $key
* @return \SimplePie\Category|null
*/
public function get_category(int $key = 0)
{
$categories = $this->get_categories();
if (isset($categories[$key])) {
return $categories[$key];
}
return null;
}
/**
* Get all categories
*
* @return \SimplePie\Category[]|null
*/
public function get_categories()
{
if ($this->categories !== null) {
return $this->categories;
}
return null;
}
/**
* Get the number of audio channels
*
* @return int|null
*/
public function get_channels()
{
if ($this->channels !== null) {
return $this->channels;
}
return null;
}
/**
* Get the copyright information
*
* @return \SimplePie\Copyright|null
*/
public function get_copyright()
{
if ($this->copyright !== null) {
return $this->copyright;
}
return null;
}
/**
* Get a single credit
*
* @param int $key
* @return \SimplePie\Credit|null
*/
public function get_credit(int $key = 0)
{
$credits = $this->get_credits();
if (isset($credits[$key])) {
return $credits[$key];
}
return null;
}
/**
* Get all credits
*
* @return Credit[]|null
*/
public function get_credits()
{
if ($this->credits !== null) {
return $this->credits;
}
return null;
}
/**
* Get the description of the enclosure
*
* @return string|null
*/
public function get_description()
{
if ($this->description !== null) {
return $this->description;
}
return null;
}
/**
* Get the duration of the enclosure
*
* @param bool $convert Convert seconds into hh:mm:ss
* @return string|int|null 'hh:mm:ss' string if `$convert` was specified, otherwise integer (or null if none found)
*/
public function get_duration(bool $convert = false)
{
if ($this->duration !== null) {
if ($convert) {
$time = \SimplePie\Misc::time_hms($this->duration);
return $time;
}
return $this->duration;
}
return null;
}
/**
* Get the expression
*
* @return string Probably one of 'sample', 'full', 'nonstop', 'clip'. Defaults to 'full'
*/
public function get_expression()
{
if ($this->expression !== null) {
return $this->expression;
}
return 'full';
}
/**
* Get the file extension
*
* @return string|null
*/
public function get_extension()
{
if ($this->link !== null) {
$url = \SimplePie\Misc::parse_url($this->link);
if ($url['path'] !== '') {
return pathinfo($url['path'], PATHINFO_EXTENSION);
}
}
return null;
}
/**
* Get the framerate (in frames-per-second)
*
* @return string|null
*/
public function get_framerate()
{
if ($this->framerate !== null) {
return $this->framerate;
}
return null;
}
/**
* Get the preferred handler
*
* @return string|null One of 'flash', 'fmedia', 'quicktime', 'wmedia', 'mp3'
*/
public function get_handler()
{
return $this->get_real_type(true);
}
/**
* Get a single hash
*
* @link http://www.rssboard.org/media-rss#media-hash
* @param int $key
* @return string|null Hash as per `media:hash`, prefixed with "$algo:"
*/
public function get_hash(int $key = 0)
{
$hashes = $this->get_hashes();
if (isset($hashes[$key])) {
return $hashes[$key];
}
return null;
}
/**
* Get all credits
*
* @return string[]|null Array of strings, see {@see get_hash()}
*/
public function get_hashes()
{
if ($this->hashes !== null) {
return $this->hashes;
}
return null;
}
/**
* Get the height
*
* @return string|null
*/
public function get_height()
{
if ($this->height !== null) {
return $this->height;
}
return null;
}
/**
* Get the language
*
* @link http://tools.ietf.org/html/rfc3066
* @return string|null Language code as per RFC 3066
*/
public function get_language()
{
if ($this->lang !== null) {
return $this->lang;
}
return null;
}
/**
* Get a single keyword
*
* @param int $key
* @return string|null
*/
public function get_keyword(int $key = 0)
{
$keywords = $this->get_keywords();
if (isset($keywords[$key])) {
return $keywords[$key];
}
return null;
}
/**
* Get all keywords
*
* @return string[]|null
*/
public function get_keywords()
{
if ($this->keywords !== null) {
return $this->keywords;
}
return null;
}
/**
* Get length
*
* @return ?int Length in bytes
*/
public function get_length()
{
if ($this->length !== null) {
return $this->length;
}
return null;
}
/**
* Get the URL
*
* @return string|null
*/
public function get_link()
{
if ($this->link !== null) {
return $this->link;
}
return null;
}
/**
* Get the medium
*
* @link http://www.rssboard.org/media-rss#media-content
* @return string|null Should be one of 'image', 'audio', 'video', 'document', 'executable'
*/
public function get_medium()
{
if ($this->medium !== null) {
return $this->medium;
}
return null;
}
/**
* Get the player URL
*
* Typically the same as {@see get_permalink()}
* @return string|null Player URL
*/
public function get_player()
{
if ($this->player !== null) {
return $this->player;
}
return null;
}
/**
* Get a single rating
*
* @param int $key
* @return \SimplePie\Rating|null
*/
public function get_rating(int $key = 0)
{
$ratings = $this->get_ratings();
if (isset($ratings[$key])) {
return $ratings[$key];
}
return null;
}
/**
* Get all ratings
*
* @return Rating[]|null
*/
public function get_ratings()
{
if ($this->ratings !== null) {
return $this->ratings;
}
return null;
}
/**
* Get a single restriction
*
* @param int $key
* @return \SimplePie\Restriction|null
*/
public function get_restriction(int $key = 0)
{
$restrictions = $this->get_restrictions();
if (isset($restrictions[$key])) {
return $restrictions[$key];
}
return null;
}
/**
* Get all restrictions
*
* @return Restriction[]|null
*/
public function get_restrictions()
{
if ($this->restrictions !== null) {
return $this->restrictions;
}
return null;
}
/**
* Get the sampling rate (in kHz)
*
* @return string|null
*/
public function get_sampling_rate()
{
if ($this->samplingrate !== null) {
return $this->samplingrate;
}
return null;
}
/**
* Get the file size (in MiB)
*
* @return float|null File size in mebibytes (1048 bytes)
*/
public function get_size()
{
$length = $this->get_length();
if ($length !== null) {
return round($length / 1048576, 2);
}
return null;
}
/**
* Get a single thumbnail
*
* @param int $key
* @return string|null Thumbnail URL
*/
public function get_thumbnail(int $key = 0)
{
$thumbnails = $this->get_thumbnails();
if (isset($thumbnails[$key])) {
return $thumbnails[$key];
}
return null;
}
/**
* Get all thumbnails
*
* @return string[]|null Array of thumbnail URLs
*/
public function get_thumbnails()
{
if ($this->thumbnails !== null) {
return $this->thumbnails;
}
return null;
}
/**
* Get the title
*
* @return string|null
*/
public function get_title()
{
if ($this->title !== null) {
return $this->title;
}
return null;
}
/**
* Get mimetype of the enclosure
*
* @see get_real_type()
* @return string|null MIME type
*/
public function get_type()
{
if ($this->type !== null) {
return $this->type;
}
return null;
}
/**
* Get the width
*
* @return string|null
*/
public function get_width()
{
if ($this->width !== null) {
return $this->width;
}
return null;
}
/**
* Embed the enclosure using `