Style tweaks in 'Handler_Public#generate_syndicated_feed()'

This commit is contained in:
wn_ 2025-06-02 20:31:23 +00:00
parent 8255f71c2e
commit 446f9dcb23

View File

@ -25,13 +25,11 @@ class Handler_Public extends Handler {
list($override_order, $skip_first_id_check) = Feeds::_order_to_override_query($order); list($override_order, $skip_first_id_check) = Feeds::_order_to_override_query($order);
if (!$override_order) { if (!$override_order) {
$override_order = "date_entered DESC, updated DESC"; $override_order = match (true) {
$feed == Feeds::FEED_PUBLISHED && !$is_cat => 'last_published DESC',
if ($feed == Feeds::FEED_PUBLISHED && !$is_cat) { $feed == Feeds::FEED_STARRED && !$is_cat => 'last_marked DESC',
$override_order = "last_published DESC"; default => 'date_entered DESC, updated DESC',
} else if ($feed == Feeds::FEED_STARRED && !$is_cat) { };
$override_order = "last_marked DESC";
}
} }
$params = array( $params = array(
@ -94,6 +92,7 @@ class Handler_Public extends Handler {
$tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true); $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url), true);
$tpl->setVariable('SELF_URL', htmlspecialchars(Config::get_self_url()), true); $tpl->setVariable('SELF_URL', htmlspecialchars(Config::get_self_url()), true);
while ($line = $result->fetch()) { while ($line = $result->fetch()) {
$line["content_preview"] = Sanitizer::sanitize(truncate_string(strip_tags($line["content"]), 100, '...')); $line["content_preview"] = Sanitizer::sanitize(truncate_string(strip_tags($line["content"]), 100, '...'));
@ -187,14 +186,14 @@ class Handler_Public extends Handler {
} }
print $tmp; print $tmp;
} else if ($format == 'json') { } else { // $format == 'json'
$feed = array(); $feed = [
'title' => $feed_title,
$feed['title'] = $feed_title; 'feed_url' => $feed_self_url,
$feed['feed_url'] = $feed_self_url; 'self_url' => Config::get_self_url(),
$feed['self_url'] = Config::get_self_url(); 'articles' => [],
$feed['articles'] = []; ];
while ($line = $result->fetch()) { while ($line = $result->fetch()) {
@ -213,30 +212,26 @@ class Handler_Public extends Handler {
}, },
$line, $feed, $is_cat, $owner_uid); $line, $feed, $is_cat, $owner_uid);
$article = array(); $article = [
'id' => $line['link'],
$article['id'] = $line['link']; 'link' => $line['link'],
$article['link'] = $line['link']; 'title' => $line['title'],
$article['title'] = $line['title']; 'content' => Sanitizer::sanitize($line['content'], false, $owner_uid, $feed_site_url, null, $line['id']),
$article['excerpt'] = $line["content_preview"]; 'updated' => date('c', strtotime($line['updated'] ?? '')),
$article['content'] = Sanitizer::sanitize($line["content"], false, $owner_uid, $feed_site_url, null, $line["id"]); 'source' => [
$article['updated'] = date('c', strtotime($line["updated"] ?? '')); 'link' => $line['site_url'] ?: Config::get_self_url(),
'title' => $line['feed_title'] ?? $feed_title,
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
]; ];
if (count($line["tags"]) > 0) { if (!empty($line['note']))
$article['tags'] = array(); $article['note'] = $line['note'];
foreach ($line["tags"] as $tag) { if (!empty($line['author']))
array_push($article['tags'], $tag); $article['author'] = $line['author'];
}
} if (count($line['tags']) > 0)
$article['tags'] = $line['tags'];
$enclosures = Article::_get_enclosures($line["id"]); $enclosures = Article::_get_enclosures($line["id"]);
@ -244,11 +239,11 @@ class Handler_Public extends Handler {
$article['enclosures'] = array(); $article['enclosures'] = array();
foreach ($enclosures as $e) { foreach ($enclosures as $e) {
$type = $e['content_type']; $article['enclosures'][] = [
$url = $e['content_url']; 'url' => $e['content_url'],
$length = $e['duration']; 'type' => $e['content_type'],
'length' => $e['duration'],
array_push($article['enclosures'], array("url" => $url, "type" => $type, "length" => $length)); ];
} }
} }