|
|
@@ -77,56 +77,73 @@ class SimplePie_Parser
|
|
|
|
|
|
public function parse(&$data, $encoding)
|
|
|
{
|
|
|
- // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
|
|
|
- if (strtoupper($encoding) === 'US-ASCII')
|
|
|
+ if (!empty($encoding))
|
|
|
{
|
|
|
- $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) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false)
|
|
|
- {
|
|
|
- $declaration = $this->registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
|
|
|
- if ($declaration->parse())
|
|
|
+ // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
|
|
|
+ if (strtoupper($encoding) === 'US-ASCII')
|
|
|
{
|
|
|
- $data = substr($data, $pos + 2);
|
|
|
- $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . $data;
|
|
|
+ $this->encoding = 'UTF-8';
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- $this->error_string = 'SimplePie bug! Please report this!';
|
|
|
- return false;
|
|
|
+ $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) === '<?xml' && strspn(substr($data, 5, 1), "\x09\x0A\x0D\x20") && ($pos = strpos($data, '?>')) !== false)
|
|
|
+ {
|
|
|
+ $declaration = $this->registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
|
|
|
+ if ($declaration->parse())
|
|
|
+ {
|
|
|
+ $data = substr($data, $pos + 2);
|
|
|
+ $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . (($declaration->standalone) ? 'yes' : 'no') . '"?>' . $data;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $this->error_string = 'SimplePie bug! Please report this!';
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ $dom = new DOMDocument();
|
|
|
+ $dom->recover = true;
|
|
|
+ $dom->strictErrorChecking = false;
|
|
|
+ $dom->loadXML($data);
|
|
|
+ $this->encoding = $encoding = $dom->encoding = 'UTF-8';
|
|
|
+ $data = $dom->saveXML();
|
|
|
+ //file_put_contents('/home/alex/public_html/alexandre.alapetite.fr/prive/FreshRSS/log/parser.log', date('c') . ' ' . 'OK' . "\n", FILE_APPEND);
|
|
|
+ }
|
|
|
+ catch (Exception $e)
|
|
|
+ {
|
|
|
}
|
|
|
|
|
|
$return = true;
|