From: Mikael Nordfeldth <mmn@hethane.se>
Date: Sat, 6 Jun 2015 14:18:22 +0000 (+0200)
Subject: OStatus update-profile.php script now finds Diaspora salmon URLs
X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b63054cb1d45764db872c392728494dee0b9bf93;p=quix0rs-gnu-social.git

OStatus update-profile.php script now finds Diaspora salmon URLs
---

diff --git a/plugins/OStatus/scripts/update-profile.php b/plugins/OStatus/scripts/update-profile.php
index ece1980442..3d72674920 100644
--- a/plugins/OStatus/scripts/update-profile.php
+++ b/plugins/OStatus/scripts/update-profile.php
@@ -54,10 +54,28 @@ print "\n";
 print "Re-running feed discovery for profile URL $oprofile->uri\n";
 // @fixme will bork where the URI isn't the profile URL for now
 $discover = new FeedDiscovery();
-$feedurl = $discover->discoverFromURL($oprofile->uri);
+try {
+    $feedurl = $discover->discoverFromURL($oprofile->uri);
+    $salmonuri = $discover->getAtomLink(Salmon::REL_SALMON)
+                    ?: $discover->getAtomLink(Salmon::NS_REPLIES);  // NS_REPLIES is deprecated
+} catch (FeedSubException $e) {
+    $acct = $oprofile->localProfile()->getAcctUri();
+    print "Could not discover feeds HTML response, trying reconstructed acct URI: " . $acct;
+    $disco = new Discovery();
+    $xrd = $disco->lookup($acct);
+    $hints = DiscoveryHints::fromXRD($xrd);
+
+    if (!array_key_exists('feedurl', $hints)) {
+        throw new FeedSubNoFeedException($acct);
+    }
+    $feedurl = $hints['feedurl'];
+    $salmonuri = array_key_exists('salmon', $hints) ? $hints['salmon'] : null;
+
+    // get the hub data too and put it in the FeedDiscovery object
+    $discover->discoverFromFeedUrl($feedurl);
+}
+
 $huburi = $discover->getHubLink();
-$salmonuri = $discover->getAtomLink(Salmon::REL_SALMON)
-                ?: $discover->getAtomLink(Salmon::NS_REPLIES);
 
 print "  Feed URL: $feedurl\n";
 print "  Hub URL: $huburi\n";