mirror of
https://git.tt-rss.org/fox/tt-rss.git
synced 2025-08-05 21:57:24 +02:00
Merge branch 'feature/syndicated-feed-improvements' into 'master'
Generated feed tweaks See merge request tt-rss/tt-rss!149
This commit is contained in:
commit
a1dcd06b3e
@ -8,23 +8,27 @@ class Handler_Public extends Handler {
|
||||
int $limit, int $offset, string $search, string $view_mode = "",
|
||||
string $format = 'atom', string $order = "", string $orig_guid = "", string $start_ts = ""): void {
|
||||
|
||||
$note_style = "background-color : #fff7d5;
|
||||
border-width : 1px; ".
|
||||
"padding : 5px; border-style : dashed; border-color : #e7d796;".
|
||||
"margin-bottom : 1em; color : #9a8c59;";
|
||||
// fail early if the requested format isn't recognized
|
||||
if (!in_array($format, ['atom', 'json'])) {
|
||||
header('Content-Type: text/plain; charset=utf-8');
|
||||
print "Unknown format: $format.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$limit) $limit = 60;
|
||||
$note_style = 'color: #9a8c59; background-color: #fff7d5; '
|
||||
. 'border: 1px dashed #e7d796; padding: 5px; margin-bottom: 1em;';
|
||||
|
||||
if (!$limit)
|
||||
$limit = 60;
|
||||
|
||||
list($override_order, $skip_first_id_check) = Feeds::_order_to_override_query($order);
|
||||
|
||||
if (!$override_order) {
|
||||
$override_order = "date_entered DESC, updated DESC";
|
||||
|
||||
if ($feed == Feeds::FEED_PUBLISHED && !$is_cat) {
|
||||
$override_order = "last_published DESC";
|
||||
} else if ($feed == Feeds::FEED_STARRED && !$is_cat) {
|
||||
$override_order = "last_marked DESC";
|
||||
}
|
||||
$override_order = match (true) {
|
||||
$feed == Feeds::FEED_PUBLISHED && !$is_cat => 'last_published DESC',
|
||||
$feed == Feeds::FEED_STARRED && !$is_cat => 'last_marked DESC',
|
||||
default => 'date_entered DESC, updated DESC',
|
||||
};
|
||||
}
|
||||
|
||||
$params = array(
|
||||
@ -75,7 +79,8 @@ class Handler_Public extends Handler {
|
||||
"/public.php?op=rss&id=$feed&key=" .
|
||||
Feeds::_get_access_key($feed, false, $owner_uid);
|
||||
|
||||
if (!$feed_site_url) $feed_site_url = Config::get_self_url();
|
||||
if (!$feed_site_url)
|
||||
$feed_site_url = Config::get_self_url();
|
||||
|
||||
if ($format == 'atom') {
|
||||
$tpl = new Templator();
|
||||
@ -83,10 +88,12 @@ class Handler_Public extends Handler {
|
||||
$tpl->readTemplateFromFile("generated_feed.txt");
|
||||
|
||||
$tpl->setVariable('FEED_TITLE', $feed_title, true);
|
||||
$tpl->setVariable('FEED_UPDATED', date('c'), true);
|
||||
$tpl->setVariable('VERSION', Config::get_version(), true);
|
||||
$tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
|
||||
|
||||
$tpl->setVariable('SELF_URL', htmlspecialchars(Config::get_self_url()), true);
|
||||
|
||||
while ($line = $result->fetch()) {
|
||||
|
||||
$line["content_preview"] = Sanitizer::sanitize(truncate_string(strip_tags($line["content"]), 100, '...'));
|
||||
@ -119,8 +126,7 @@ class Handler_Public extends Handler {
|
||||
$content = DiskCache::rewrite_urls($content);
|
||||
|
||||
if ($line['note']) {
|
||||
$content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" .
|
||||
$content;
|
||||
$content = "<div style=\"$note_style\">Article note: " . $line['note'] . "</div>" . $content;
|
||||
$tpl->setVariable('ARTICLE_NOTE', htmlspecialchars($line['note']), true);
|
||||
}
|
||||
|
||||
@ -147,7 +153,7 @@ class Handler_Public extends Handler {
|
||||
foreach ($enclosures as $e) {
|
||||
$type = htmlspecialchars($e['content_type']);
|
||||
$url = htmlspecialchars($e['content_url']);
|
||||
$length = $e['duration'] ? $e['duration'] : 1;
|
||||
$length = $e['duration'] ?: 1;
|
||||
|
||||
$tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url, true);
|
||||
$tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type, true);
|
||||
@ -180,14 +186,14 @@ class Handler_Public extends Handler {
|
||||
}
|
||||
|
||||
print $tmp;
|
||||
} else if ($format == 'json') {
|
||||
} else { // $format == 'json'
|
||||
|
||||
$feed = array();
|
||||
|
||||
$feed['title'] = $feed_title;
|
||||
$feed['feed_url'] = $feed_self_url;
|
||||
$feed['self_url'] = Config::get_self_url();
|
||||
$feed['articles'] = [];
|
||||
$feed = [
|
||||
'title' => $feed_title,
|
||||
'feed_url' => $feed_self_url,
|
||||
'self_url' => Config::get_self_url(),
|
||||
'articles' => [],
|
||||
];
|
||||
|
||||
while ($line = $result->fetch()) {
|
||||
|
||||
@ -206,30 +212,26 @@ class Handler_Public extends Handler {
|
||||
},
|
||||
$line, $feed, $is_cat, $owner_uid);
|
||||
|
||||
$article = array();
|
||||
|
||||
$article['id'] = $line['link'];
|
||||
$article['link'] = $line['link'];
|
||||
$article['title'] = $line['title'];
|
||||
$article['excerpt'] = $line["content_preview"];
|
||||
$article['content'] = Sanitizer::sanitize($line["content"], false, $owner_uid, $feed_site_url, null, $line["id"]);
|
||||
$article['updated'] = date('c', strtotime($line["updated"] ?? ''));
|
||||
|
||||
if (!empty($line['note'])) $article['note'] = $line['note'];
|
||||
if (!empty($line['author'])) $article['author'] = $line['author'];
|
||||
|
||||
$article['source'] = [
|
||||
'link' => $line['site_url'] ? $line["site_url"] : Config::get_self_url(),
|
||||
'title' => $line['feed_title'] ?? $feed_title
|
||||
$article = [
|
||||
'id' => $line['link'],
|
||||
'link' => $line['link'],
|
||||
'title' => $line['title'],
|
||||
'content' => Sanitizer::sanitize($line['content'], false, $owner_uid, $feed_site_url, null, $line['id']),
|
||||
'updated' => date('c', strtotime($line['updated'] ?? '')),
|
||||
'source' => [
|
||||
'link' => $line['site_url'] ?: Config::get_self_url(),
|
||||
'title' => $line['feed_title'] ?? $feed_title,
|
||||
],
|
||||
];
|
||||
|
||||
if (count($line["tags"]) > 0) {
|
||||
$article['tags'] = array();
|
||||
if (!empty($line['note']))
|
||||
$article['note'] = $line['note'];
|
||||
|
||||
foreach ($line["tags"] as $tag) {
|
||||
array_push($article['tags'], $tag);
|
||||
}
|
||||
}
|
||||
if (!empty($line['author']))
|
||||
$article['author'] = $line['author'];
|
||||
|
||||
if (count($line['tags']) > 0)
|
||||
$article['tags'] = $line['tags'];
|
||||
|
||||
$enclosures = Article::_get_enclosures($line["id"]);
|
||||
|
||||
@ -237,11 +239,11 @@ class Handler_Public extends Handler {
|
||||
$article['enclosures'] = array();
|
||||
|
||||
foreach ($enclosures as $e) {
|
||||
$type = $e['content_type'];
|
||||
$url = $e['content_url'];
|
||||
$length = $e['duration'];
|
||||
|
||||
array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length));
|
||||
$article['enclosures'][] = [
|
||||
'url' => $e['content_url'],
|
||||
'type' => $e['content_type'],
|
||||
'length' => $e['duration'],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -251,9 +253,6 @@ class Handler_Public extends Handler {
|
||||
header("Content-Type: application/json; charset=utf-8");
|
||||
print json_encode($feed);
|
||||
|
||||
} else {
|
||||
header("Content-Type: text/plain; charset=utf-8");
|
||||
print "Unknown format: $format.";
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
<feed xmlns="http://www.w3.org/2005/Atom">
|
||||
<title>${FEED_TITLE}</title>
|
||||
<generator uri="http://tt-rss.org/">Tiny Tiny RSS/${VERSION}</generator>
|
||||
<updated>${ARTICLE_UPDATED_ATOM}</updated>
|
||||
<updated>${FEED_UPDATED}</updated>
|
||||
<id>${FEED_URL}</id>
|
||||
<link href="${FEED_URL}" rel="self"/>
|
||||
<!-- $BeginBlock feed_hub -->
|
||||
|
Loading…
Reference in New Issue
Block a user