From 33fff2686946021314a24feef61032beaf48e7a4 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 22 Feb 2021 10:00:50 +0300 Subject: [PATCH] reinstate HOOK_RENDER_ENCLOSURE --- classes/article.php | 23 ++++++++++++++++++----- classes/pluginhost.php | 4 ++-- js/Article.js | 6 +----- plugins/af_youtube_embed/init.php | 6 +++--- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/classes/article.php b/classes/article.php index dd1470caa..acd83694c 100755 --- a/classes/article.php +++ b/classes/article.php @@ -343,6 +343,7 @@ class Article extends Handler_Protected { } $rv = [ + 'formatted' => '', 'entries' => [] ]; @@ -358,12 +359,24 @@ class Article extends Handler_Protected { // this is highly approximate $enc["filename"] = basename($enc["content_url"]); - PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_ENCLOSURE_ENTRY, - function ($result) use (&$enc) { - $enc = $result; + $rendered_enc = ""; + PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_RENDER_ENCLOSURE, + function ($result) use (&$rendered_enc) { + $rendered_enc = $result; }, - $enc, $id); - array_push($rv['entries'], $enc); + $enc, $id, $rv); + + if ($rendered_enc) { + $rv['formatted'] .= $rendered_enc; + } else { + PluginHost::getInstance()->chain_hooks_callback(PluginHost::HOOK_ENCLOSURE_ENTRY, + function ($result) use (&$enc) { + $enc = $result; + }, + $enc, $id, $rv); + + array_push($rv['entries'], $enc); + } } return $rv; diff --git a/classes/pluginhost.php b/classes/pluginhost.php index d50c5a706..a05938111 100755 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -51,11 +51,11 @@ class PluginHost { const HOOK_FORMAT_ENCLOSURES = "hook_format_enclosures"; // hook__format_enclosures($rv, $result, $id, $always_display_enclosures, $article_content, $hide_images) (byref) const HOOK_SUBSCRIBE_FEED = "hook_subscribe_feed"; // hook_subscribe_feed($contents, $url, $auth_login, $auth_pass) (byref) const HOOK_HEADLINES_BEFORE = "hook_headlines_before"; // hook_headlines_before($feed, $is_cat, $qfh_ret) - const HOOK_RENDER_ENCLOSURE = "hook_render_enclosure"; // hook_render_enclosure($entry, $hide_images) + const HOOK_RENDER_ENCLOSURE = "hook_render_enclosure"; // hook_render_enclosure($entry, $id, $rv) const HOOK_ARTICLE_FILTER_ACTION = "hook_article_filter_action"; // hook_article_filter_action($article, $action) const HOOK_ARTICLE_EXPORT_FEED = "hook_article_export_feed"; // hook_article_export_feed($line, $feed, $is_cat, $owner_uid) (byref) const HOOK_MAIN_TOOLBAR_BUTTON = "hook_main_toolbar_button"; // hook_main_toolbar_button() - const HOOK_ENCLOSURE_ENTRY = "hook_enclosure_entry"; // hook_enclosure_entry($row, $id) (byref) + const HOOK_ENCLOSURE_ENTRY = "hook_enclosure_entry"; // hook_enclosure_entry($entry, $id, $rv) (byref) const HOOK_FORMAT_ARTICLE = "hook_format_article"; // hook_format_article($html, $row) const HOOK_FORMAT_ARTICLE_CDM = "hook_format_article_cdm"; /* RIP */ const HOOK_FEED_BASIC_INFO = "hook_feed_basic_info"; // hook_feed_basic_info($basic_info, $fetch_url, $owner_uid, $feed_id, $auth_login, $auth_pass) (byref) diff --git a/js/Article.js b/js/Article.js index d039882ec..5f695561c 100644 --- a/js/Article.js +++ b/js/Article.js @@ -150,12 +150,8 @@ const Article = { ).join("")}`; }, renderEnclosures: function (enclosures) { - - // enclosure list was handled by backend (HOOK_FORMAT_ENCLOSURES) - if (enclosures.formatted) - return enclosures.formatted; - return ` + ${enclosures.formatted} ${enclosures.can_inline ? `
${enclosures.entries.map((enc) => { diff --git a/plugins/af_youtube_embed/init.php b/plugins/af_youtube_embed/init.php index db82dc9f5..6309aac02 100644 --- a/plugins/af_youtube_embed/init.php +++ b/plugins/af_youtube_embed/init.php @@ -23,9 +23,9 @@ class Af_Youtube_Embed extends Plugin { $matches = array(); - if (preg_match("/\/\/www\.youtube\.com\/v\/([\w-]+)/", $entry["url"], $matches) || - preg_match("/\/\/www\.youtube\.com\/watch?v=([\w-]+)/", $entry["url"], $matches) || - preg_match("/\/\/youtu.be\/([\w-]+)/", $entry["url"], $matches)) { + if (preg_match("/\/\/www\.youtube\.com\/v\/([\w-]+)/", $entry["content_url"], $matches) || + preg_match("/\/\/www\.youtube\.com\/watch?v=([\w-]+)/", $entry["content_url"], $matches) || + preg_match("/\/\/youtu.be\/([\w-]+)/", $entry["content_url"], $matches)) { $vid_id = $matches[1];