]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/GContact.php
Add 'addon' folder as 'Friendica\Addon' namespace for autoload
[friendica.git] / src / Model / GContact.php
index cc7775377924fb1b69882c44e7c79a30d3928367..337a938a747c86fc2d307355753bd63e13a1ae55 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;
@@ -16,8 +17,7 @@ use Friendica\Network\Probe;
 use Friendica\Protocol\PortableContact;
 use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
-
-require_once 'include/dba.php';
+use Friendica\Util\Strings;
 
 /**
  * @brief This class handles GlobalContact related functions
@@ -145,13 +145,13 @@ class GContact
                $alternate = PortableContact::alternateOStatusUrl($gcontact['url']);
 
                // The global contacts should contain the original picture, not the cached one
-               if (($gcontact['generation'] != 1) && stristr(normalise_link($gcontact['photo']), normalise_link(System::baseUrl()."/photo/"))) {
+               if (($gcontact['generation'] != 1) && stristr(Strings::normaliseLink($gcontact['photo']), Strings::normaliseLink(System::baseUrl()."/photo/"))) {
                        $gcontact['photo'] = "";
                }
 
                if (!isset($gcontact['network'])) {
                        $condition = ["`uid` = 0 AND `nurl` = ? AND `network` != '' AND `network` != ?",
-                               normalise_link($gcontact['url']), Protocol::STATUSNET];
+                               Strings::normaliseLink($gcontact['url']), Protocol::STATUSNET];
                        $contact = DBA::selectFirst('contact', ['network'], $condition);
                        if (DBA::isResult($contact)) {
                                $gcontact['network'] = $contact["network"];
@@ -159,7 +159,7 @@ class GContact
 
                        if (($gcontact['network'] == "") || ($gcontact['network'] == Protocol::OSTATUS)) {
                                $condition = ["`uid` = 0 AND `alias` IN (?, ?) AND `network` != '' AND `network` != ?",
-                                       $gcontact['url'], normalise_link($gcontact['url']), Protocol::STATUSNET];
+                                       $gcontact['url'], Strings::normaliseLink($gcontact['url']), Protocol::STATUSNET];
                                $contact = DBA::selectFirst('contact', ['network'], $condition);
                                if (DBA::isResult($contact)) {
                                        $gcontact['network'] = $contact["network"];
@@ -171,7 +171,7 @@ class GContact
                $gcontact['network'] = '';
 
                $fields = ['network', 'updated', 'server_url', 'url', 'addr'];
-               $gcnt = DBA::selectFirst('gcontact', $fields, ['nurl' => normalise_link($gcontact['url'])]);
+               $gcnt = DBA::selectFirst('gcontact', $fields, ['nurl' => Strings::normaliseLink($gcontact['url'])]);
                if (DBA::isResult($gcnt)) {
                        if (!isset($gcontact['network']) && ($gcnt["network"] != Protocol::STATUSNET)) {
                                $gcontact['network'] = $gcnt["network"];
@@ -179,7 +179,7 @@ class GContact
                        if ($gcontact['updated'] <= DBA::NULL_DATETIME) {
                                $gcontact['updated'] = $gcnt["updated"];
                        }
-                       if (!isset($gcontact['server_url']) && (normalise_link($gcnt["server_url"]) != normalise_link($gcnt["url"]))) {
+                       if (!isset($gcontact['server_url']) && (Strings::normaliseLink($gcnt["server_url"]) != Strings::normaliseLink($gcnt["url"]))) {
                                $gcontact['server_url'] = $gcnt["server_url"];
                        }
                        if (!isset($gcontact['addr'])) {
@@ -204,8 +204,8 @@ class GContact
 
                        if ($alternate && ($gcontact['network'] == Protocol::OSTATUS)) {
                                // Delete the old entry - if it exists
-                               if (DBA::exists('gcontact', ['nurl' => normalise_link($orig_profile)])) {
-                                       DBA::delete('gcontact', ['nurl' => normalise_link($orig_profile)]);
+                               if (DBA::exists('gcontact', ['nurl' => Strings::normaliseLink($orig_profile)])) {
+                                       DBA::delete('gcontact', ['nurl' => Strings::normaliseLink($orig_profile)]);
                                }
                        }
                }
@@ -256,7 +256,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'];
                }
@@ -428,7 +428,7 @@ class GContact
                //      return $list;
                //}
 
-               $network = [Protocol::DFRN];
+               $network = [Protocol::DFRN, Protocol::ACTIVITYPUB];
 
                if (Config::get('system', 'diaspora_enabled')) {
                        $network[] = Protocol::DIASPORA;
@@ -449,7 +449,7 @@ class GContact
                        where uid = %d and not gcontact.nurl in ( select nurl from contact where uid = %d )
                        AND NOT `gcontact`.`name` IN (SELECT `name` FROM `contact` WHERE `uid` = %d)
                        AND NOT `gcontact`.`id` IN (SELECT `gcid` FROM `gcign` WHERE `uid` = %d)
-                       AND `gcontact`.`updated` >= '%s'
+                       AND `gcontact`.`updated` >= '%s' AND NOT `gcontact`.`hide`
                        AND `gcontact`.`last_contact` >= `gcontact`.`last_failure`
                        AND `gcontact`.`network` IN (%s)
                        GROUP BY `glink`.`gcid` ORDER BY `gcontact`.`updated` DESC,`total` DESC LIMIT %d, %d",
@@ -518,7 +518,7 @@ class GContact
         */
        public static function updateSuggestions()
        {
-               $a = get_app();
+               $a = \get_app();
 
                $done = [];
 
@@ -588,7 +588,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 +605,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 +629,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;
                }
 
@@ -657,7 +657,7 @@ class GContact
 
                DBA::lock('gcontact');
                $fields = ['id', 'last_contact', 'last_failure', 'network'];
-               $gcnt = DBA::selectFirst('gcontact', $fields, ['nurl' => normalise_link($contact["url"])]);
+               $gcnt = DBA::selectFirst('gcontact', $fields, ['nurl' => Strings::normaliseLink($contact["url"])]);
                if (DBA::isResult($gcnt)) {
                        $gcontact_id = $gcnt["id"];
 
@@ -682,7 +682,7 @@ class GContact
                                DBA::escape($contact["addr"]),
                                DBA::escape($contact["network"]),
                                DBA::escape($contact["url"]),
-                               DBA::escape(normalise_link($contact["url"])),
+                               DBA::escape(Strings::normaliseLink($contact["url"])),
                                DBA::escape($contact["photo"]),
                                DBA::escape(DateTimeFormat::utcNow()),
                                DBA::escape(DateTimeFormat::utcNow()),
@@ -692,7 +692,7 @@ class GContact
                                intval($contact["generation"])
                        );
 
-                       $condition = ['nurl' => normalise_link($contact["url"])];
+                       $condition = ['nurl' => Strings::normaliseLink($contact["url"])];
                        $cnt = DBA::selectFirst('gcontact', ['id', 'network'], $condition, ['order' => ['id']]);
                        if (DBA::isResult($cnt)) {
                                $gcontact_id = $cnt["id"];
@@ -702,7 +702,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"]);
                }
 
@@ -792,7 +792,7 @@ class GContact
                                $contact["server_url"] = $data['baseurl'];
                        }
                } else {
-                       $contact["server_url"] = normalise_link($contact["server_url"]);
+                       $contact["server_url"] = Strings::normaliseLink($contact["server_url"]);
                }
 
                if (($contact["addr"] == "") && ($contact["server_url"] != "") && ($contact["nick"] != "")) {
@@ -807,21 +807,21 @@ 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"]];
+                                       Strings::normaliseLink($contact["url"]), $contact["generation"]];
                        $contact["updated"] = DateTimeFormat::utc($contact["updated"]);
 
                        $updated = ['photo' => $contact['photo'], 'name' => $contact['name'],
@@ -841,9 +841,9 @@ class GContact
                        // This is used for the shadow copies of public items.
                        /// @todo Check if we really should do this.
                        // 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]);
+                       $public_contact = DBA::selectFirst('contact', ['id'], ['nurl' => Strings::normaliseLink($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"]);
 
@@ -862,7 +862,7 @@ class GContact
                                                'location' => $contact['location'], 'about' => $contact['about']];
 
                                // Don't update the birthday field if not set or invalid
-                               if (empty($contact['birthday']) || ($contact['birthday'] < '0001-01-01')) {
+                               if (empty($contact['birthday']) || ($contact['birthday'] <= DBA::NULL_DATE)) {
                                        unset($fields['bd']);
                                }
 
@@ -885,7 +885,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;
                }
 
@@ -916,7 +916,7 @@ class GContact
                );
 
                if (!DBA::isResult($r)) {
-                       logger('Cannot find user with uid=' . $uid, LOGGER_INFO);
+                       Logger::log('Cannot find user with uid=' . $uid, Logger::INFO);
                        return false;
                }
 
@@ -953,7 +953,7 @@ 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";
 
@@ -964,8 +964,8 @@ class GContact
 
                $statistics = json_decode($curlResult->getBody());
 
-               if (!empty($statistics->config)) {
-                       if ($statistics->config->instance_with_ssl) {
+               if (!empty($statistics->config->instance_address)) {
+                       if (!empty($statistics->config->instance_with_ssl)) {
                                $server = "https://";
                        } else {
                                $server = "http://";
@@ -974,8 +974,8 @@ class GContact
                        $server .= $statistics->config->instance_address;
 
                        $hostname = $statistics->config->instance_address;
-               } elseif (!empty($statistics)) {
-                       if ($statistics->instance_with_ssl) {
+               } elseif (!empty($statistics->instance_address)) {
+                       if (!empty($statistics->instance_with_ssl)) {
                                $server = "https://";
                        } else {
                                $server = "http://";