]> git.mxchange.org Git - friendica.git/commitdiff
Issue 8675: reduce requests of foreign pages
authorMichael <heluecht@pirati.ca>
Mon, 1 Jun 2020 21:52:31 +0000 (21:52 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 1 Jun 2020 21:52:31 +0000 (21:52 +0000)
src/Model/APContact.php
src/Model/Contact.php
src/Model/Profile.php
src/Module/RemoteFollow.php
src/Network/CurlResult.php
src/Network/Probe.php
static/dbstructure.config.php

index 17a4d22a2580a9424dd5d40cb0270506ffa49f66..1c5b5d211470957aa3b802ffe118dd6da5a131ea 100644 (file)
@@ -276,15 +276,17 @@ class APContact
                        }
                }
 
-               $parts = parse_url($apcontact['url']);
-               unset($parts['path']);
-               $baseurl = Network::unparseURL($parts);
-
-               // Check if the address is resolvable or the profile url is identical with the base url of the system
-               if (self::addrToUrl($apcontact['addr'], $apcontact['url']) || Strings::compareLink($apcontact['url'], $baseurl)) {
-                       $apcontact['baseurl'] = $baseurl;
-               } else {
-                       $apcontact['addr'] = null;
+               if (empty($fetched_contact['baseurl']) || $update) {
+                       $parts = parse_url($apcontact['url']);
+                       unset($parts['path']);
+                       $baseurl = Network::unparseURL($parts);
+
+                       // Check if the address is resolvable or the profile url is identical with the base url of the system
+                       if (self::addrToUrl($apcontact['addr'], $apcontact['url']) || Strings::compareLink($apcontact['url'], $baseurl)) {
+                               $apcontact['baseurl'] = $baseurl;
+                       } else {
+                               $apcontact['addr'] = null;
+                       }
                }
 
                if (empty($apcontact['baseurl'])) {
@@ -312,7 +314,7 @@ class APContact
                        DBA::delete('apcontact', ['url' => $url]);
                }
 
-               Logger::log('Updated profile for ' . $url, Logger::DEBUG);
+               Logger::info('Updated profile', ['url' => $url]);
 
                return $apcontact;
        }
index 3ddefdd0bffd8d04a4a36ed39987cc666444eede..e881398df8b9ce893de96f520646934b6117a73c 100644 (file)
@@ -2085,7 +2085,7 @@ class Contact
                // These fields aren't updated by this routine:
                // 'xmpp', 'sensitive'
 
-               $fields = ['uid', 'avatar', 'name', 'nick', 'location', 'keywords', 'about',
+               $fields = ['uid', 'avatar', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe',
                        'unsearchable', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco',
                        'network', 'alias', 'baseurl', 'gsid', 'forum', 'prv', 'contact-type', 'pubkey'];
                $contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
index ed55354b685b7884a78c7fc88ee0b81e3878faea..2b1546db49ef077eee04f0e763bf4a4a2532859e 100644 (file)
@@ -27,7 +27,6 @@ use Friendica\Content\Widget\ContactBlock;
 use Friendica\Core\Cache\Duration;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
-use Friendica\Network\Probe;
 use Friendica\Core\Protocol;
 use Friendica\Core\Renderer;
 use Friendica\Core\Session;
@@ -772,7 +771,7 @@ class Profile
                $_SESSION['visitor_handle'] = $visitor['addr'];
                $_SESSION['visitor_home'] = $visitor['url'];
                $_SESSION['my_url'] = $visitor['url'];
-               $_SESSION['remote_comment'] = Probe::getRemoteFollowLink($visitor['url']);
+               $_SESSION['remote_comment'] = $visitor['subscribe'];
 
                Session::setVisitorsContacts();
 
index 8e4da3c63ba3acab4c9bfe969db26583e5717bcf..bf71b077fd01888deae74dface5203b012ded31f 100644 (file)
@@ -67,17 +67,14 @@ class RemoteFollow extends BaseModule
                        return;
                }
 
-               // Fetch link for the "remote follow" functionality of the given profile
-               $follow_link_template = Probe::getRemoteFollowLink($url);
-
-               if (empty($follow_link_template)) {
+               if (empty($data['subscribe'])) {
                        notice(DI::l10n()->t("Remote subscription can't be done for your network. Please subscribe directly on your system."));
                        return;
                }
 
-               Logger::notice('Remote request', ['url' => $url, 'follow' => $a->profile['url'], 'remote' => $follow_link_template]);
+               Logger::notice('Remote request', ['url' => $url, 'follow' => $a->profile['url'], 'remote' => $data['subscribe']]);
                
-               // Substitute our user's feed URL into $follow_link_template
+               // Substitute our user's feed URL into $data['subscribe']
                // Send the subscriber home to subscribe
                // Diaspora needs the uri in the format user@domain.tld
                if ($data['network'] == Protocol::DIASPORA) {
@@ -86,7 +83,7 @@ class RemoteFollow extends BaseModule
                        $uri = urlencode($a->profile['url']);
                }
        
-               $follow_link = str_replace('{uri}', $uri, $follow_link_template);
+               $follow_link = str_replace('{uri}', $uri, $data['subscribe']);
                System::externalRedirect($follow_link);
        }
 
index 44263716bce9cb499be52ddd8b8d0a5b09d3a5e1..51ef77f54b7f70192be752228df31595ec20394a 100644 (file)
@@ -22,6 +22,7 @@
 namespace Friendica\Network;
 
 use Friendica\Core\Logger;
+use Friendica\Core\System;
 use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Util\Network;
 
@@ -166,7 +167,7 @@ class CurlResult
                }
 
                if (!$this->isSuccess) {
-                       Logger::log('error: ' . $this->url . ': ' . $this->returnCode . ' - ' . $this->error, Logger::INFO);
+                       Logger::error('error', ['url' => $this->url, 'code' => $this->returnCode, 'error'  => $this->error, 'callstack' => System::callstack(20)]);
                        Logger::log('debug: ' . print_r($this->info, true), Logger::DATA);
                }
 
index 28f58c467621ef7f72e4e66b948c756fcae6701c..0a67b246130e5741b173e5d24d226ea419369bdd 100644 (file)
@@ -85,7 +85,7 @@ class Probe
        {
                $fields = ["name", "nick", "guid", "url", "addr", "alias", "photo", "account-type",
                                "community", "keywords", "location", "about", "hide",
-                               "batch", "notify", "poll", "request", "confirm", "poco",
+                               "batch", "notify", "poll", "request", "confirm", "subscribe", "poco",
                                "following", "followers", "inbox", "outbox", "sharedinbox",
                                "priority", "network", "pubkey", "baseurl", "gsid"];
 
@@ -270,37 +270,15 @@ class Probe
                return $profile_link;
        }
 
-       /**
-        * Get the link for the remote follow page for a given profile link
-        *
-        * @param sting $profile
-        * @return string Remote follow page link
-        */
-       public static function getRemoteFollowLink(string $profile)
-       {
-               $follow_link = '';
-
-               $links = self::lrdd($profile);
-
-               if (!empty($links) && is_array($links)) {
-                       foreach ($links as $link) {
-                               if ($link['@attributes']['rel'] === ActivityNamespace::OSTATUSSUB) {
-                                       $follow_link = $link['@attributes']['template'];
-                               }
-                       }
-               }
-               return $follow_link;
-       }
-
        /**
         * Check an URI for LRDD data
         *
-        * @param string $uri Address that should be probed
+        * @param string $uri     Address that should be probed
         *
         * @return array uri data
         * @throws HTTPException\InternalServerErrorException
         */
-       public static function lrdd($uri)
+       public static function lrdd(string $uri)
        {
                $lrdd = self::hostMeta($uri);
                $webfinger = null;
@@ -423,7 +401,9 @@ class Probe
                        $ap_profile = ActivityPub::probeProfile($uri);
 
                        if (empty($data) || (!empty($ap_profile) && empty($network) && (($data['network'] ?? '') != Protocol::DFRN))) {
+                               $subscribe = $data['subscribe'];
                                $data = $ap_profile;
+                               $data['subscribe'] = $subscribe;
                        } elseif (!empty($ap_profile)) {
                                $ap_profile['batch'] = '';
                                $data = array_merge($ap_profile, $data);
@@ -597,6 +577,28 @@ class Probe
                return $webfinger;
        }
 
+       /**
+        * Fetch the "subscribe" and add it to the result
+        *
+        * @param array $result
+        * @param array $webfinger
+        * @return array result
+        */
+       private static function getSubscribeLink(array $result, array $webfinger)
+       {
+               if (empty($webfinger['links'])) {
+                       return $result;
+               }
+
+               foreach ($webfinger['links'] as $link) {
+                       if ($link['rel'] === ActivityNamespace::OSTATUSSUB) {
+                               $result['subscribe'] = $link['template'];
+                       }
+               }
+
+               return $result;
+       }
+
        /**
         * Fetch information (protocol endpoints and user information) about a given uri
         *
@@ -720,7 +722,7 @@ class Probe
 
                $result = false;
 
-               Logger::log("Probing ".$uri, Logger::DEBUG);
+               Logger::info("Probing", ['uri' => $uri]);
 
                if (in_array($network, ["", Protocol::DFRN])) {
                        $result = self::dfrn($webfinger);
@@ -751,6 +753,8 @@ class Probe
                        }
                }
 
+               $result = self::getSubscribeLink($result, $webfinger);
+
                if (empty($result["network"])) {
                        $result["network"] = Protocol::PHANTOM;
                }
index 9fccdf14b633327fe7632ef0f3dbdce65df97f08..1a70201258f26bedfb50dfa086b638f663137095 100755 (executable)
@@ -54,7 +54,7 @@
 use Friendica\Database\DBA;
 
 if (!defined('DB_UPDATE_VERSION')) {
-       define('DB_UPDATE_VERSION', 1351);
+       define('DB_UPDATE_VERSION', 1352);
 }
 
 return [
@@ -141,6 +141,7 @@ return [
                        "notify" => ["type" => "varchar(255)", "comment" => ""],
                        "poll" => ["type" => "varchar(255)", "comment" => ""],
                        "confirm" => ["type" => "varchar(255)", "comment" => ""],
+                       "subscribe" => ["type" => "varchar(255)", "comment" => ""],
                        "poco" => ["type" => "varchar(255)", "comment" => ""],
                        "aes_allow" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
                        "ret-aes" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],