Commit dea75ddd authored by Malcolm Blaney's avatar Malcolm Blaney

Fix Reader module to check for NULL returned by SimplePie API. Also

improved display by using title as content when content not provided.
Improved Mf2 Parser by not returning unused rels values by default.
parent 3f032d79
Pipeline #37602784 passed with stage
in 1 minute and 15 seconds
......@@ -686,13 +686,26 @@ class Reader extends Base {
$this->Log('Reader->AddFeed 3: ' . $mysqli->error);
}
if (!$feed_exists) {
$title = $mysqli->escape_string($feed->get_title());
$description = $mysqli->escape_string($feed->get_description());
$html_url = $mysqli->escape_string(trim($feed->get_link(), ' /'));
$language = $mysqli->escape_string($feed->get_language());
$image_url = $mysqli->escape_string($feed->get_image_url());
$image_title = $mysqli->escape_string($feed->get_image_title());
$image_link = $mysqli->escape_string($feed->get_image_link());
$us_title = $feed->get_title();
$us_description = $feed->get_description();
$us_html_url = trim($feed->get_link(), ' /');
$us_language = $feed->get_language();
$us_image_url = $feed->get_image_url();
$us_image_title = $feed->get_image_title();
$us_image_link = $feed->get_image_link();
$title = isset($us_title) ? $mysqli->escape_string($us_title) : '';
$description = isset($us_description) ?
$mysqli->escape_string($us_description) : '';
$html_url = isset($us_html_url) ?
$mysqli->escape_string($us_html_url) : '';
$language = isset($us_language) ?
$mysqli->escape_string($us_language) : '';
$image_url = isset($us_image_url) ?
$mysqli->escape_string($us_image_url) : '';
$image_title = isset($us_image_title) ?
$mysqli->escape_string($us_image_title) : '';
$image_link = isset($us_image_link) ?
$mysqli->escape_string($us_image_link) : '';
// These feeds change the html_url link so it's hard to identify their
// item groups, and we want to use the group info to know whether an
// item should be automatically syndicated to the silos they came from.
......@@ -791,13 +804,26 @@ class Reader extends Base {
}
// Update feed attributes once a day, in case anything has changed.
if ($daily) {
$title = $mysqli->escape_string($feed->get_title());
$description = $mysqli->escape_string($feed->get_description());
$html_url = $mysqli->escape_string(trim($feed->get_link(), ' /'));
$language = $mysqli->escape_string($feed->get_language());
$image_url = $mysqli->escape_string($feed->get_image_url());
$image_title = $mysqli->escape_string($feed->get_image_title());
$image_link = $mysqli->escape_string($feed->get_image_link());
$us_title = $feed->get_title();
$us_description = $feed->get_description();
$us_html_url = trim($feed->get_link(), ' /');
$us_language = $feed->get_language();
$us_image_url = $feed->get_image_url();
$us_image_title = $feed->get_image_title();
$us_image_link = $feed->get_image_link();
$title = isset($us_title) ? $mysqli->escape_string($us_title) : '';
$description = isset($us_description) ?
$mysqli->escape_string($us_description) : '';
$html_url = isset($us_html_url) ?
$mysqli->escape_string($us_html_url) : '';
$language = isset($us_language) ?
$mysqli->escape_string($us_language) : '';
$image_url = isset($us_image_url) ?
$mysqli->escape_string($us_image_url) : '';
$image_title = isset($us_image_title) ?
$mysqli->escape_string($us_image_title) : '';
$image_link = isset($us_image_link) ?
$mysqli->escape_string($us_image_link) : '';
if (strpos($xml_url, 'https://facebook-atom.appspot.com') === 0) {
$html_url = 'https://facebook-atom.appspot.com';
$scheme = $this->user->config->Secure() ? 'https://' : 'http://';
......@@ -2029,15 +2055,20 @@ class Reader extends Base {
private function SaveItem($item, $xml_url, $purifier) {
$us_permalink = $item->get_permalink();
// If the item doesn't have a permalink then skip it.
if (!$us_permalink) return false;
if (!isset($us_permalink)) return false;
$us_title = '';
// Twitter feed is a special case, there are no titles on Twitter but
// there is usually a modified version of the content in the item's title.
if (strpos($xml_url, 'https://twitter-atom.appspot.com') !== 0) {
$us_title = strip_tags($item->get_title());
$us_title = $item->get_title();
$us_title = isset($us_title) ? strip_tags($us_title) : '';
}
$us_content = $this->RemoveDuplicateImages($item->get_description());
$us_content = $item->get_description();
$us_content = isset($us_content) ?
$this->RemoveDuplicateImages($us_content) : '';
$us_guid = $item->get_id();
// If title is the same as the start of the stripped version of content,
// set it to the empty string. Also need to check for newlines and extra
// spaces created because of the removed tags possibly having their own
......@@ -2051,19 +2082,16 @@ class Reader extends Base {
if ($check_title === $check_content) {
$us_title = '';
}
else if ($us_content === '') {
// Use title as content when content not provided, it looks better.
$us_content = $us_title;
$us_title = '';
}
else if (strlen($us_title) > 140) {
// For long titles check if there's any content, if not assume p-name
// was just used instead of e-content and use the title as content.
if ($us_content === '') {
$us_content = $us_title;
$us_title = '';
}
else {
// Otherwise assume that long titles are probably the same as the
// content, but the comparison failed. In this case show a shortened
// version of the title.
$us_title = substr($us_title, 0, 100) . '...';
}
// Otherwise assume that long titles are probably the same as the
// content, but the comparison failed. In this case show a shortened
// version of the title.
$us_title = substr($us_title, 0, 100) . '...';
}
}
......@@ -2072,7 +2100,7 @@ class Reader extends Base {
$permalink = $mysqli->escape_string($us_permalink);
$title = $mysqli->escape_string($us_title);
$content = $mysqli->escape_string($purifier->purify($us_content));
$guid = $mysqli->escape_string($item->get_id());
$guid = isset($us_guid) ? $mysqli->escape_string($us_guid) : '';
// guid's must be less than 100 characters as they are used as a primary
// key in the reader_items table, so use md5 to keep them unique.
if (strlen($guid) > 100) $guid = md5($guid);
......@@ -2088,10 +2116,10 @@ class Reader extends Base {
$us_author = '';
if ($item_author = $item->get_author()) {
$us_author = $item_author->get_email();
if (!$us_author) {
if (!isset($us_author)) {
$us_author = $item_author->get_name();
}
if (!$us_author) {
if (!isset($us_author)) {
$us_author = $item_author->get_link();
}
}
......@@ -2160,7 +2188,8 @@ class Reader extends Base {
// yet, give it the current time so it's not buried. Don't want to see
// all items when subscribing to a new feed, so don't change the
// timestamp when older than 48 hours.
$timestamp = strtotime($item->get_date());
$date = $item->get_date();
$timestamp = isset($date) ? strtotime($date) : false;
if (!$timestamp || $timestamp > time() ||
($timestamp < strtotime('-1 hour') &&
$timestamp > strtotime('-48 hours'))) {
......
......@@ -315,6 +315,9 @@ class Parser {
/** @var bool Whether to include alternates object (dropped from spec in favor of rel-urls) */
public $enableAlternates = false;
/** @var bool Whether to include rels object */
public $enableRels = false;
/**
* Elements upgraded to mf2 during backcompat
* @var SplObjectStorage
......@@ -1334,20 +1337,24 @@ class Parser {
$this->convertClassic = $convertClassic;
$mfs = $this->parse_recursive($context);
// Parse rels
list($rels, $rel_urls, $alternates) = $this->parseRelsAndAlternates();
if ($this->enableRels) {
// Parse rels
list($rels, $rel_urls, $alternates) = $this->parseRelsAndAlternates();
$top = array(
'items' => array_values(array_filter($mfs)),
'rels' => $rels,
'rel-urls' => $rel_urls,
);
$top = array(
'items' => array_values(array_filter($mfs)),
'rels' => $rels,
'rel-urls' => $rel_urls,
);
if ($this->enableAlternates && count($alternates)) {
$top['alternates'] = $alternates;
if ($this->enableAlternates && count($alternates)) {
$top['alternates'] = $alternates;
}
return $top;
}
return $top;
return array('items' => array_values(array_filter($mfs)));
}
......@@ -1451,8 +1458,11 @@ class Parser {
public function parseFromId($id, $convertClassic=true) {
$matches = $this->xpath->query("//*[@id='{$id}']");
if (empty($matches))
return array('items' => array(), 'rels' => array(), 'alternates' => array());
if (empty($matches)) {
return $this->enableRels ?
array('items' => array(), 'rels' => array(), 'alternates' => array()) :
array('items' => array());
}
return $this->parse($convertClassic, $matches->item(0));
}
......
......@@ -230,7 +230,7 @@ class Control extends Base {
$site_style = ['"",".control","position","sticky"',
'"",".control","width","100%"',
'"",".control","top","0"',
'"",".control","z-index","50"',
'"",".control","z-index","200"',
'"",".control","height","48px"',
'"",".control","display","none"',
'"",".control .wrapper","height","38px"',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment