api: rewrite article urls at the very end to prevent plugins which expect source URLs from breaking

This commit is contained in:
Andrew Dolgov 2021-02-15 09:40:43 +03:00
parent 52a86c5e38
commit 868b9b476e
1 changed files with 18 additions and 14 deletions

View File

@ -754,8 +754,6 @@ class API extends Handler {
} else { } else {
$headline_row["content"] = $line["content"]; $headline_row["content"] = $line["content"];
} }
$headline_row["content"] = DiskCache::rewriteUrls($headline_row['content']);
} }
// unify label output to ease parsing // unify label output to ease parsing
@ -776,22 +774,28 @@ class API extends Handler {
$headline_row["note"] = $line["note"]; $headline_row["note"] = $line["note"];
$headline_row["lang"] = $line["lang"]; $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, list ($flavor_image, $flavor_stream, $flavor_kind) = Article::get_article_image($enclosures,
function ($result) use (&$headline_row) { $line["content"], // unsanitized
$headline_row = $result; $line["site_url"]);
},
$hook_object);
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; /* optional */
$headline_row["flavor_stream"] = $flavor_stream; if ($flavor_kind)
$headline_row["flavor_kind"] = $flavor_kind;
/* optional */ PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_RENDER_ARTICLE_API,
if ($flavor_kind) function ($result) use (&$headline_row) {
$headline_row["flavor_kind"] = $flavor_kind; $headline_row = $result;
},
$hook_object);
$headline_row["content"] = DiskCache::rewriteUrls($headline_row['content']);
}
array_push($headlines, $headline_row); array_push($headlines, $headline_row);
} }