From fa2ebcd0a25e6c350d7105753ca4f3e37cf7f464 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 8 Feb 2021 17:03:34 +0300 Subject: api: rewrite a few more hooks --- classes/api.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'classes/api.php') diff --git a/classes/api.php b/classes/api.php index 7125e52aa..4b9c44073 100755 --- a/classes/api.php +++ b/classes/api.php @@ -352,9 +352,11 @@ class API extends Handler { $article["content"] = $line["content"]; } - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) { - $article = $p->hook_render_article_api(array("article" => $article)); - } + PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_RENDER_ARTICLE_API, + function ($result) use (&$article) { + $article = $result; + }, + ["article" => $article]); $article['content'] = DiskCache::rewriteUrls($article['content']); @@ -703,9 +705,12 @@ class API extends Handler { if (!is_numeric($result)) { while ($line = $result->fetch()) { $line["content_preview"] = truncate_string(strip_tags($line["content"]), $excerpt_length); - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_QUERY_HEADLINES) as $p) { - $line = $p->hook_query_headlines($line, $excerpt_length, true); - } + + PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_QUERY_HEADLINES, + function ($result) use (&$line) { + $line = $result; + }, + $line, $excerpt_length); $is_updated = ($line["last_read"] == "" && ($line["unread"] != "t" && $line["unread"] != "1")); @@ -781,9 +786,11 @@ class API extends Handler { $headline_row["note"] = $line["note"]; $headline_row["lang"] = $line["lang"]; - foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE_API) as $p) { - $headline_row = $p->hook_render_article_api(array("headline" => $headline_row)); - } + PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_RENDER_ARTICLE_API, + function ($result) use (&$headline_row) { + $headline_row = $result; + }, + ["headline" => $headline_row]); $headline_row["content"] = DiskCache::rewriteUrls($headline_row['content']); -- cgit v1.2.3