]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/PortableContact.php
Fix an error and a notice
[friendica.git] / src / Protocol / PortableContact.php
index 655929f52987d2ef5c3a6714658c35d54cae50c0..9ba6a4b9008b91eabe5e6691ec71d8ac629d2aba 100644 (file)
@@ -57,7 +57,7 @@ class PortableContact
        public static function loadWorker($cid, $uid = 0, $zcid = 0, $url = null)
        {
                // Call the function "load" via the worker
-               Worker::add(PRIORITY_LOW, "DiscoverPoCo", "load", (int)$cid, (int)$uid, (int)$zcid, $url);
+               Worker::add(PRIORITY_LOW, 'FetchPoCo', (int)$cid, (int)$uid, (int)$zcid, $url);
        }
 
        /**
@@ -214,56 +214,6 @@ class PortableContact
                DBA::delete('glink', $condition);
        }
 
-       public static function alternateOStatusUrl($url)
-       {
-               return(preg_match("=https?://.+/user/\d+=ism", $url, $matches));
-       }
-
-       public static function updateNeeded($created, $updated, $last_failure, $last_contact)
-       {
-               $now = strtotime(DateTimeFormat::utcNow());
-
-               if ($updated > $last_contact) {
-                       $contact_time = strtotime($updated);
-               } else {
-                       $contact_time = strtotime($last_contact);
-               }
-
-               $failure_time = strtotime($last_failure);
-               $created_time = strtotime($created);
-
-               // If there is no "created" time then use the current time
-               if ($created_time <= 0) {
-                       $created_time = $now;
-               }
-
-               // If the last contact was less than 24 hours then don't update
-               if (($now - $contact_time) < (60 * 60 * 24)) {
-                       return false;
-               }
-
-               // If the last failure was less than 24 hours then don't update
-               if (($now - $failure_time) < (60 * 60 * 24)) {
-                       return false;
-               }
-
-               // If the last contact was less than a week ago and the last failure is older than a week then don't update
-               //if ((($now - $contact_time) < (60 * 60 * 24 * 7)) && ($contact_time > $failure_time))
-               //      return false;
-
-               // If the last contact time was more than a week ago and the contact was created more than a week ago, then only try once a week
-               if ((($now - $contact_time) > (60 * 60 * 24 * 7)) && (($now - $created_time) > (60 * 60 * 24 * 7)) && (($now - $failure_time) < (60 * 60 * 24 * 7))) {
-                       return false;
-               }
-
-               // If the last contact time was more than a month ago and the contact was created more than a month ago, then only try once a month
-               if ((($now - $contact_time) > (60 * 60 * 24 * 30)) && (($now - $created_time) > (60 * 60 * 24 * 30)) && (($now - $failure_time) < (60 * 60 * 24 * 30))) {
-                       return false;
-               }
-
-               return true;
-       }
-
        /**
         * @brief Returns a list of all known servers
         * @return array List of server urls
@@ -315,74 +265,11 @@ class PortableContact
 
                        if (!DBA::isResult($r)) {
                                Logger::log("Call server check for server ".$server_url, Logger::DEBUG);
-                               Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $server_url);
+                               Worker::add(PRIORITY_LOW, 'UpdateGServer', $server_url);
                        }
                }
        }
 
-       private static function discoverFederation()
-       {
-               $last = Config::get('poco', 'last_federation_discovery');
-
-               if ($last) {
-                       $next = $last + (24 * 60 * 60);
-
-                       if ($next > time()) {
-                               return;
-                       }
-               }
-
-               // Discover Friendica, Hubzilla and Diaspora servers
-               $curlResult = Network::fetchUrl("http://the-federation.info/pods.json");
-
-               if (!empty($curlResult)) {
-                       $servers = json_decode($curlResult, true);
-
-                       if (!empty($servers['pods'])) {
-                               foreach ($servers['pods'] as $server) {
-                                       Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", "https://" . $server['host']);
-                               }
-                       }
-               }
-
-               // Disvover Mastodon servers
-               if (!Config::get('system', 'ostatus_disabled')) {
-                       $accesstoken = Config::get('system', 'instances_social_key');
-
-                       if (!empty($accesstoken)) {
-                               $api = 'https://instances.social/api/1.0/instances/list?count=0';
-                               $header = ['Authorization: Bearer '.$accesstoken];
-                               $curlResult = Network::curl($api, false, ['headers' => $header]);
-
-                               if ($curlResult->isSuccess()) {
-                                       $servers = json_decode($curlResult->getBody(), true);
-
-                                       foreach ($servers['instances'] as $server) {
-                                               $url = (is_null($server['https_score']) ? 'http' : 'https') . '://' . $server['name'];
-                                               Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $url);
-                                       }
-                               }
-                       }
-               }
-
-               // Currently disabled, since the service isn't available anymore.
-               // It is not removed since I hope that there will be a successor.
-               // Discover GNU Social Servers.
-               //if (!Config::get('system','ostatus_disabled')) {
-               //      $serverdata = "http://gstools.org/api/get_open_instances/";
-
-               //      $curlResult = Network::curl($serverdata);
-               //      if ($curlResult->isSuccess()) {
-               //              $servers = json_decode($result->getBody(), true);
-
-               //              foreach($servers['data'] as $server)
-               //                      GServer::check($server['instance_address']);
-               //      }
-               //}
-
-               Config::set('poco', 'last_federation_discovery', time());
-       }
-
        public static function discoverSingleServer($id)
        {
                $server = DBA::selectFirst('gserver', ['poco', 'nurl', 'url', 'network'], ['id' => $id]);
@@ -455,48 +342,6 @@ class PortableContact
                }
        }
 
-       public static function discover($complete = false)
-       {
-               // Update the server list
-               self::discoverFederation();
-
-               $no_of_queries = 5;
-
-               $requery_days = intval(Config::get('system', 'poco_requery_days'));
-
-               if ($requery_days == 0) {
-                       $requery_days = 7;
-               }
-
-               $last_update = date('c', time() - (60 * 60 * 24 * $requery_days));
-
-               $gservers = q("SELECT `id`, `url`, `nurl`, `network`
-                       FROM `gserver`
-                       WHERE `last_contact` >= `last_failure`
-                       AND `poco` != ''
-                       AND `last_poco_query` < '%s'
-                       ORDER BY RAND()", DBA::escape($last_update)
-               );
-
-               if (DBA::isResult($gservers)) {
-                       foreach ($gservers as $gserver) {
-                               if (!GServer::check($gserver['url'], $gserver['network'])) {
-                                       // The server is not reachable? Okay, then we will try it later
-                                       $fields = ['last_poco_query' => DateTimeFormat::utcNow()];
-                                       DBA::update('gserver', $fields, ['nurl' => $gserver['nurl']]);
-                                       continue;
-                               }
-
-                               Logger::log('Update directory from server ' . $gserver['url'] . ' with ID ' . $gserver['id'], Logger::DEBUG);
-                               Worker::add(PRIORITY_LOW, 'UpdateServerDirectory', (int)$gserver['id']);
-
-                               if (!$complete && ( --$no_of_queries == 0)) {
-                                       break;
-                               }
-                       }
-               }
-       }
-
        private static function discoverServerUsers(array $data, array $server)
        {
                if (!isset($data['entry'])) {
@@ -647,5 +492,4 @@ class PortableContact
                }
                return $success;
        }
-
 }