Update of picoFeed

This commit is contained in:
Frederic Guillot 2013-06-26 19:30:46 -04:00
parent 7ac57db487
commit 271241fcf7
5 changed files with 14 additions and 7 deletions

View File

@ -1,5 +1,4 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

View File

@ -38,4 +38,4 @@
<?php endforeach ?>
</section>
<?php endif ?>
<?php endif ?>

View File

@ -17,7 +17,7 @@ class Rss20 extends Parser
$namespaces = $xml->getNamespaces(true);
if ($xml->channel->link->count() > 1) {
if ($xml->channel->link && $xml->channel->link->count() > 1) {
foreach ($xml->channel->link as $xml_link) {
@ -40,6 +40,9 @@ class Rss20 extends Parser
$this->updated = isset($xml->channel->pubDate) ? (string) $xml->channel->pubDate : (string) $xml->channel->lastBuildDate;
$this->updated = $this->updated ? strtotime($this->updated) : time();
// RSS feed might be empty
if (! $xml->channel->item) return $this;
foreach ($xml->channel->item as $entry) {
$item = new \StdClass;

View File

@ -51,11 +51,15 @@ class Reader
public function getFirstTag($data)
{
// Strip HTML comments
$data = preg_replace('/<!--(.*)-->/Uis', '', $data);
// Strip HTML comments (max of 5,000 characters long to prevent crashing)
$data = preg_replace('/<!--(.{0,5000}?)-->/Uis', '', $data);
// Strip Doctype
$data = preg_replace('/<!DOCTYPE(.*)>/Uis', '', $data);
/* Strip Doctype:
* Doctype needs to be within the first 500 characters. (Ideally the first!)
* If it's not found by then, we need to stop looking to prevent PREG
* from reaching max backtrack depth and crashing.
*/
$data = preg_replace('/^.{0,500}<!DOCTYPE([^>]*)>/Uis', '', $data);
// Find <?xml version....
if (strpos($data, '<?xml') !== false) {

View File

@ -124,6 +124,7 @@ class RemoteResource
curl_setopt($ch, CURLOPT_USERAGENT, $this->user_agent);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_ENCODING, '');
// Don't check SSL certificates (for auto-signed certificates...)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);