]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/GContact.php
Merge pull request #6065 from annando/fix-forum
[friendica.git] / src / Model / GContact.php
index 6f068889eebe2e96b910cd35b5e5585e231e379c..398fc77588766a3ed6609d5ef91ca20aaf2c0a24 100644 (file)
@@ -8,6 +8,7 @@ namespace Friendica\Model;
 
 use Exception;
 use Friendica\Core\Config;
+use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
@@ -61,11 +62,11 @@ class GContact
                $search .= "%";
 
                $results = DBA::p("SELECT `nurl` FROM `gcontact`
-                       WHERE NOT `hide` AND `network` IN (?, ?, ?) AND
+                       WHERE NOT `hide` AND `network` IN (?, ?, ?, ?) AND
                                ((`last_contact` >= `last_failure`) OR (`updated` >= `last_failure`)) AND
                                (`addr` LIKE ? OR `name` LIKE ? OR `nick` LIKE ?) $extra_sql
                                GROUP BY `nurl` ORDER BY `nurl` DESC LIMIT 1000",
-                       Protocol::DFRN, $ostatus, $diaspora, $search, $search, $search
+                       Protocol::DFRN, Protocol::ACTIVITYPUB, $ostatus, $diaspora, $search, $search, $search
                );
 
                $gcontacts = [];
@@ -138,7 +139,7 @@ class GContact
                }
 
                // Assure that there are no parameter fragments in the profile url
-               if (in_array($gcontact['network'], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) {
+               if (in_array($gcontact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, ""])) {
                        $gcontact['url'] = self::cleanContactUrl($gcontact['url']);
                }
 
@@ -176,7 +177,7 @@ class GContact
                        if (!isset($gcontact['network']) && ($gcnt["network"] != Protocol::STATUSNET)) {
                                $gcontact['network'] = $gcnt["network"];
                        }
-                       if ($gcontact['updated'] <= NULL_DATE) {
+                       if ($gcontact['updated'] <= DBA::NULL_DATETIME) {
                                $gcontact['updated'] = $gcnt["updated"];
                        }
                        if (!isset($gcontact['server_url']) && (normalise_link($gcnt["server_url"]) != normalise_link($gcnt["url"]))) {
@@ -214,7 +215,7 @@ class GContact
                        throw new Exception('No name and photo for URL '.$gcontact['url']);
                }
 
-               if (!in_array($gcontact['network'], [Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
+               if (!in_array($gcontact['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])) {
                        throw new Exception('No federated network ('.$gcontact['network'].') detected for URL '.$gcontact['url']);
                }
 
@@ -256,7 +257,7 @@ class GContact
                        intval($cid)
                );
 
-               // logger("countCommonFriends: $uid $cid {$r[0]['total']}");
+               // Logger::log("countCommonFriends: $uid $cid {$r[0]['total']}");
                if (DBA::isResult($r)) {
                        return $r[0]['total'];
                }
@@ -457,7 +458,7 @@ class GContact
                        intval($uid),
                        intval($uid),
                        intval($uid),
-                       DBA::escape(NULL_DATE),
+                       DBA::NULL_DATETIME,
                        $sql_network,
                        intval($start),
                        intval($limit)
@@ -468,7 +469,7 @@ class GContact
                        * Uncommented because the result of the queries are to big to store it in the cache.
                        * We need to decide if we want to change the db column type or if we want to delete it.
                        */
-                       //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $r, CACHE_FIVE_MINUTES);
+                       //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $r, Cache::FIVE_MINUTES);
 
                        return $r;
                }
@@ -486,7 +487,7 @@ class GContact
                        intval($uid),
                        intval($uid),
                        intval($uid),
-                       DBA::escape(NULL_DATE),
+                       DBA::NULL_DATETIME,
                        $sql_network,
                        intval($start),
                        intval($limit)
@@ -509,7 +510,7 @@ class GContact
                * Uncommented because the result of the queries are to big to store it in the cache.
                * We need to decide if we want to change the db column type or if we want to delete it.
                */
-               //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $list, CACHE_FIVE_MINUTES);
+               //Cache::set("suggestion_query:".$uid.":".$start.":".$limit, $list, Cache::FIVE_MINUTES);
                return $list;
        }
 
@@ -588,7 +589,7 @@ class GContact
                }
 
                if ($new_url != $url) {
-                       logger("Cleaned contact url ".$url." to ".$new_url." - Called by: ".System::callstack(), LOGGER_DEBUG);
+                       Logger::log("Cleaned contact url ".$url." to ".$new_url." - Called by: ".System::callstack(), Logger::DEBUG);
                }
 
                return $new_url;
@@ -605,7 +606,7 @@ class GContact
                if (($contact["network"] == Protocol::OSTATUS) && PortableContact::alternateOStatusUrl($contact["url"])) {
                        $data = Probe::uri($contact["url"]);
                        if ($contact["network"] == Protocol::OSTATUS) {
-                               logger("Fix primary url from ".$contact["url"]." to ".$data["url"]." - Called by: ".System::callstack(), LOGGER_DEBUG);
+                               Logger::log("Fix primary url from ".$contact["url"]." to ".$data["url"]." - Called by: ".System::callstack(), Logger::DEBUG);
                                $contact["url"] = $data["url"];
                                $contact["addr"] = $data["addr"];
                                $contact["alias"] = $data["alias"];
@@ -629,12 +630,12 @@ class GContact
                $last_contact_str = '';
 
                if (empty($contact["network"])) {
-                       logger("Empty network for contact url ".$contact["url"]." - Called by: ".System::callstack(), LOGGER_DEBUG);
+                       Logger::log("Empty network for contact url ".$contact["url"]." - Called by: ".System::callstack(), Logger::DEBUG);
                        return false;
                }
 
                if (in_array($contact["network"], [Protocol::PHANTOM])) {
-                       logger("Invalid network for contact url ".$contact["url"]." - Called by: ".System::callstack(), LOGGER_DEBUG);
+                       Logger::log("Invalid network for contact url ".$contact["url"]." - Called by: ".System::callstack(), Logger::DEBUG);
                        return false;
                }
 
@@ -651,7 +652,7 @@ class GContact
                self::fixAlternateContactAddress($contact);
 
                // Remove unwanted parts from the contact url (e.g. "?zrl=...")
-               if (in_array($contact["network"], [Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
+               if (in_array($contact["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) {
                        $contact["url"] = self::cleanContactUrl($contact["url"]);
                }
 
@@ -702,7 +703,7 @@ class GContact
                DBA::unlock();
 
                if ($doprobing) {
-                       logger("Last Contact: ". $last_contact_str." - Last Failure: ".$last_failure_str." - Checking: ".$contact["url"], LOGGER_DEBUG);
+                       Logger::log("Last Contact: ". $last_contact_str." - Last Failure: ".$last_failure_str." - Checking: ".$contact["url"], Logger::DEBUG);
                        Worker::add(PRIORITY_LOW, 'GProbe', $contact["url"]);
                }
 
@@ -807,19 +808,19 @@ class GContact
                if ((($contact["generation"] > 0) && ($contact["generation"] <= $public_contact[0]["generation"])) || ($public_contact[0]["generation"] == 0)) {
                        foreach ($fields as $field => $data) {
                                if ($contact[$field] != $public_contact[0][$field]) {
-                                       logger("Difference for contact ".$contact["url"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$public_contact[0][$field]."'", LOGGER_DEBUG);
+                                       Logger::log("Difference for contact ".$contact["url"]." in field '".$field."'. New value: '".$contact[$field]."', old value '".$public_contact[0][$field]."'", Logger::DEBUG);
                                        $update = true;
                                }
                        }
 
                        if ($contact["generation"] < $public_contact[0]["generation"]) {
-                               logger("Difference for contact ".$contact["url"]." in field 'generation'. new value: '".$contact["generation"]."', old value '".$public_contact[0]["generation"]."'", LOGGER_DEBUG);
+                               Logger::log("Difference for contact ".$contact["url"]." in field 'generation'. new value: '".$contact["generation"]."', old value '".$public_contact[0]["generation"]."'", Logger::DEBUG);
                                $update = true;
                        }
                }
 
                if ($update) {
-                       logger("Update gcontact for ".$contact["url"], LOGGER_DEBUG);
+                       Logger::log("Update gcontact for ".$contact["url"], Logger::DEBUG);
                        $condition = ['`nurl` = ? AND (`generation` = 0 OR `generation` >= ?)',
                                        normalise_link($contact["url"]), $contact["generation"]];
                        $contact["updated"] = DateTimeFormat::utc($contact["updated"]);
@@ -843,7 +844,7 @@ class GContact
                        // The quality of the gcontact table is mostly lower than the public contact
                        $public_contact = DBA::selectFirst('contact', ['id'], ['nurl' => normalise_link($contact["url"]), 'uid' => 0]);
                        if (DBA::isResult($public_contact)) {
-                               logger("Update public contact ".$public_contact["id"], LOGGER_DEBUG);
+                               Logger::log("Update public contact ".$public_contact["id"], Logger::DEBUG);
 
                                Contact::updateAvatar($contact["photo"], 0, $public_contact["id"]);
 
@@ -885,7 +886,7 @@ class GContact
                $data = Probe::uri($url);
 
                if (in_array($data["network"], [Protocol::PHANTOM])) {
-                       logger("Invalid network for contact url ".$data["url"]." - Called by: ".System::callstack(), LOGGER_DEBUG);
+                       Logger::log("Invalid network for contact url ".$data["url"]." - Called by: ".System::callstack(), Logger::DEBUG);
                        return;
                }
 
@@ -915,6 +916,11 @@ class GContact
                        intval($uid)
                );
 
+               if (!DBA::isResult($r)) {
+                       Logger::log('Cannot find user with uid=' . $uid, Logger::INFO);
+                       return false;
+               }
+
                $location = Profile::formatLocation(
                        ["locality" => $r[0]["locality"], "region" => $r[0]["region"], "country-name" => $r[0]["country-name"]]
                );
@@ -948,16 +954,16 @@ class GContact
         */
        public static function fetchGsUsers($server)
        {
-               logger("Fetching users from GNU Social server ".$server, LOGGER_DEBUG);
+               Logger::log("Fetching users from GNU Social server ".$server, Logger::DEBUG);
 
                $url = $server."/main/statistics";
 
-               $result = Network::curl($url);
-               if (!$result["success"]) {
+               $curlResult = Network::curl($url);
+               if (!$curlResult->isSuccess()) {
                        return false;
                }
 
-               $statistics = json_decode($result["body"]);
+               $statistics = json_decode($curlResult->getBody());
 
                if (!empty($statistics->config)) {
                        if ($statistics->config->instance_with_ssl) {
@@ -990,7 +996,7 @@ class GContact
                                                "addr" => $user->nickname."@".$hostname,
                                                "nick" => $user->nickname,
                                                "network" => Protocol::OSTATUS,
-                                               "photo" => System::baseUrl()."/images/person-175.jpg"];
+                                               "photo" => System::baseUrl()."/images/person-300.jpg"];
 
                                if (isset($user->bio)) {
                                        $contact["about"] = $user->bio;