From 6b785c4c14c5c79bd9ae9b4e51350257a32fdb67 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Sat, 10 Jun 2023 14:16:32 +0300 Subject: add hook_pre_subscribe --- init.php | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'init.php') diff --git a/init.php b/init.php index 3191bcb..cd19e8c 100644 --- a/init.php +++ b/init.php @@ -27,14 +27,31 @@ class Af_Lemmy extends Plugin { $host->add_hook($host::HOOK_PRE_SUBSCRIBE, $this); } - // TODO: maybe support other federated instances like beehaw? whitelist? function hook_pre_subscribe(&$url, $auth_login, $auth_pass) { $origin_domain = parse_url($url, PHP_URL_HOST); if (in_array($origin_domain, $this->lemmy_domains)) { + $content = UrlHelper::fetch(["url" => $url, + "login" => $auth_login, + "pass" => $auth_pass, + "http_accept" => "text/*"]); + if ($content) { + $doc = new DOMDocument(); + if (@$doc->loadHTML($content)) { + $xpath = new DOMXPath($doc); + + /** @var ?DOMElement $rss_url */ + $rss_url = $xpath->query("//a[contains(@href, '/feeds/')]")->item(0); + + if ($rss_url) { + $url = UrlHelper::rewrite_relative($url, $rss_url->getAttribute('href')); + return true; + } + } + } } return false; -- cgit v1.2.3