From 868b9b476e3d534672bb7deb940eea2059b90494 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 15 Feb 2021 09:40:43 +0300 Subject: [PATCH] api: rewrite article urls at the very end to prevent plugins which expect source URLs from breaking --- classes/api.php | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/classes/api.php b/classes/api.php index 9299c34ea..6debad2f7 100755 --- a/classes/api.php +++ b/classes/api.php @@ -754,8 +754,6 @@ class API extends Handler { } else { $headline_row["content"] = $line["content"]; } - - $headline_row["content"] = DiskCache::rewriteUrls($headline_row['content']); } // unify label output to ease parsing @@ -776,22 +774,28 @@ class API extends Handler { $headline_row["note"] = $line["note"]; $headline_row["lang"] = $line["lang"]; - $hook_object = ["headline" => &$headline_row]; + if ($show_content) { + $hook_object = ["headline" => &$headline_row]; - PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_RENDER_ARTICLE_API, - function ($result) use (&$headline_row) { - $headline_row = $result; - }, - $hook_object); + list ($flavor_image, $flavor_stream, $flavor_kind) = Article::get_article_image($enclosures, + $line["content"], // unsanitized + $line["site_url"]); - list ($flavor_image, $flavor_stream, $flavor_kind) = Article::get_article_image($enclosures, $line["content"], $line["site_url"]); + $headline_row["flavor_image"] = $flavor_image; + $headline_row["flavor_stream"] = $flavor_stream; - $headline_row["flavor_image"] = $flavor_image; - $headline_row["flavor_stream"] = $flavor_stream; + /* optional */ + if ($flavor_kind) + $headline_row["flavor_kind"] = $flavor_kind; - /* optional */ - if ($flavor_kind) - $headline_row["flavor_kind"] = $flavor_kind; + PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_RENDER_ARTICLE_API, + function ($result) use (&$headline_row) { + $headline_row = $result; + }, + $hook_object); + + $headline_row["content"] = DiskCache::rewriteUrls($headline_row['content']); + } array_push($headlines, $headline_row); }