summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2023-06-10 14:16:32 +0300
committerAndrew Dolgov <[email protected]>2023-06-10 14:16:32 +0300
commit6b785c4c14c5c79bd9ae9b4e51350257a32fdb67 (patch)
treed93a09861402b2449f5130610f613028ec681ba1
parentfe31e18fd0928ee2efa71973568f0a2e800d259a (diff)
add hook_pre_subscribe
-rw-r--r--init.php19
1 files changed, 18 insertions, 1 deletions
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;