]> git.mxchange.org Git - friendica.git/blobdiff - src/Protocol/PortableContact.php
Merge pull request #4429 from MrPetovan/bug/4426-handle-auth-exceptions
[friendica.git] / src / Protocol / PortableContact.php
index e70e67366cf8333beae39f09a6efe522dcb50351..201f9c8c048b799078ab1dcc036ca53fbfd6f09a 100644 (file)
@@ -15,6 +15,7 @@ use Friendica\Database\DBM;
 use Friendica\Model\GContact;
 use Friendica\Model\Profile;
 use Friendica\Network\Probe;
+use Friendica\Util\DateTimeFormat;
 use Friendica\Util\Network;
 use dba;
 use DOMDocument;
@@ -22,7 +23,6 @@ use DOMXPath;
 use Exception;
 
 require_once 'include/dba.php';
-require_once 'include/datetime.php';
 require_once 'include/html2bbcode.php';
 
 class PortableContact
@@ -143,7 +143,7 @@ class PortableContact
                        }
 
                        if (isset($entry->updated)) {
-                               $updated = date("Y-m-d H:i:s", strtotime($entry->updated));
+                               $updated = date(DateTimeFormat::MYSQL, strtotime($entry->updated));
                        }
 
                        if (isset($entry->network)) {
@@ -314,7 +314,7 @@ class PortableContact
                $contact = ["url" => $profile];
 
                if ($gcontacts[0]["created"] <= NULL_DATE) {
-                       $contact['created'] = datetime_convert();
+                       $contact['created'] = DateTimeFormat::utcNow();
                }
 
                if ($force) {
@@ -337,7 +337,7 @@ class PortableContact
                if ($server_url != "") {
                        if (!self::checkServer($server_url, $gcontacts[0]["network"], $force)) {
                                if ($force) {
-                                       $fields = ['last_failure' => datetime_convert()];
+                                       $fields = ['last_failure' => DateTimeFormat::utcNow()];
                                        dba::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
                                }
 
@@ -411,14 +411,14 @@ class PortableContact
 
                                                // Set the date of the last contact
                                                /// @todo By now the function "update_gcontact" doesn't work with this field
-                                               //$contact["last_contact"] = datetime_convert();
+                                               //$contact["last_contact"] = DateTimeFormat::utcNow();
 
                                                $contact = array_merge($contact, $noscrape);
 
                                                GContact::update($contact);
 
                                                if (trim($noscrape["updated"]) != "") {
-                                                       $fields = ['last_contact' => datetime_convert()];
+                                                       $fields = ['last_contact' => DateTimeFormat::utcNow()];
                                                        dba::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
 
                                                        logger("Profile ".$profile." was last updated at ".$noscrape["updated"]." (noscrape)", LOGGER_DEBUG);
@@ -467,7 +467,7 @@ class PortableContact
                }
 
                if (($data["poll"] == "") || (in_array($data["network"], [NETWORK_FEED, NETWORK_PHANTOM]))) {
-                       $fields = ['last_failure' => datetime_convert()];
+                       $fields = ['last_failure' => DateTimeFormat::utcNow()];
                        dba::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
 
                        logger("Profile ".$profile." wasn't reachable (profile)", LOGGER_DEBUG);
@@ -483,7 +483,7 @@ class PortableContact
                $feedret = Network::curl($data["poll"]);
 
                if (!$feedret["success"]) {
-                       $fields = ['last_failure' => datetime_convert()];
+                       $fields = ['last_failure' => DateTimeFormat::utcNow()];
                        dba::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
 
                        logger("Profile ".$profile." wasn't reachable (no feed)", LOGGER_DEBUG);
@@ -501,14 +501,16 @@ class PortableContact
                $last_updated = "";
 
                foreach ($entries as $entry) {
-                       $published = $xpath->query('atom:published/text()', $entry)->item(0)->nodeValue;
-                       $updated = $xpath->query('atom:updated/text()', $entry)->item(0)->nodeValue;
+                       $published = DateTimeFormat::utc($xpath->query('atom:published/text()', $entry)->item(0)->nodeValue);
+                       $updated   = DateTimeFormat::utc($xpath->query('atom:updated/text()'  , $entry)->item(0)->nodeValue);
 
-                       if ($last_updated < $published)
+                       if ($last_updated < $published) {
                                $last_updated = $published;
+                       }
 
-                       if ($last_updated < $updated)
+                       if ($last_updated < $updated) {
                                $last_updated = $updated;
+                       }
                }
 
                // Maybe there aren't any entries. Then check if it is a valid feed
@@ -517,7 +519,8 @@ class PortableContact
                                $last_updated = NULL_DATE;
                        }
                }
-               $fields = ['updated' => DBM::date($last_updated), 'last_contact' => DBM::date()];
+
+               $fields = ['updated' => $last_updated, 'last_contact' => DateTimeFormat::utcNow()];
                dba::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
 
                if (($gcontacts[0]["generation"] == 0)) {
@@ -527,12 +530,12 @@ class PortableContact
 
                logger("Profile ".$profile." was last updated at ".$last_updated, LOGGER_DEBUG);
 
-               return($last_updated);
+               return $last_updated;
        }
 
        public static function updateNeeded($created, $updated, $last_failure, $last_contact)
        {
-               $now = strtotime(datetime_convert());
+               $now = strtotime(DateTimeFormat::utcNow());
 
                if ($updated > $last_contact) {
                        $contact_time = strtotime($updated);
@@ -921,7 +924,7 @@ class PortableContact
                $gserver = dba::selectFirst('gserver', [], ['nurl' => normalise_link($server_url)]);
                if (DBM::is_result($gserver)) {
                        if ($gserver["created"] <= NULL_DATE) {
-                               $fields = ['created' => datetime_convert()];
+                               $fields = ['created' => DateTimeFormat::utcNow()];
                                $condition = ['nurl' => normalise_link($server_url)];
                                dba::update('gserver', $fields, $condition);
                        }
@@ -968,7 +971,7 @@ class PortableContact
                // Mastodon uses the "@" for user profiles.
                // But this can be misunderstood.
                if (parse_url($server_url, PHP_URL_USER) != '') {
-                       dba::update('gserver', ['last_failure' => datetime_convert()], ['nurl' => normalise_link($server_url)]);
+                       dba::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]);
                        return false;
                }
 
@@ -984,7 +987,7 @@ class PortableContact
                if (DBM::is_result($gserver) && ($orig_server_url == $server_url) &&
                        ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT)) {
                        logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
-                       dba::update('gserver', ['last_failure' => datetime_convert()], ['nurl' => normalise_link($server_url)]);
+                       dba::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]);
                        return false;
                }
 
@@ -999,7 +1002,7 @@ class PortableContact
                        // Quit if there is a timeout
                        if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) {
                                logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
-                               dba::update('gserver', ['last_failure' => datetime_convert()], ['nurl' => normalise_link($server_url)]);
+                               dba::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]);
                                return false;
                        }
 
@@ -1331,9 +1334,9 @@ class PortableContact
 
                if ($failure) {
                        $last_contact = $orig_last_contact;
-                       $last_failure = datetime_convert();
+                       $last_failure = DateTimeFormat::utcNow();
                } else {
-                       $last_contact = datetime_convert();
+                       $last_contact = DateTimeFormat::utcNow();
                        $last_failure = $orig_last_failure;
                }
 
@@ -1361,7 +1364,7 @@ class PortableContact
                        dba::update('gserver', $fields, ['nurl' => normalise_link($server_url)]);
                } elseif (!$failure) {
                        $fields['nurl'] = normalise_link($server_url);
-                       $fields['created'] = datetime_convert();
+                       $fields['created'] = DateTimeFormat::utcNow();
                        dba::insert('gserver', $fields);
                }
                logger("End discovery for server " . $server_url, LOGGER_DEBUG);
@@ -1506,7 +1509,7 @@ class PortableContact
                                        $timeframe = 30;
                                }
 
-                               $updatedSince = date("Y-m-d H:i:s", time() - $timeframe * 86400);
+                               $updatedSince = date(DateTimeFormat::MYSQL, time() - $timeframe * 86400);
 
                                // Fetch all global contacts from the other server (Not working with Redmatrix and Friendica versions before 3.3)
                                $url = $server["poco"]."/@global?updatedSince=".$updatedSince."&fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
@@ -1525,7 +1528,7 @@ class PortableContact
                                }
                        }
 
-                       $fields = ['last_poco_query' => datetime_convert()];
+                       $fields = ['last_poco_query' => DateTimeFormat::utcNow()];
                        dba::update('gserver', $fields, ['nurl' => $server["nurl"]]);
 
                        return true;
@@ -1534,7 +1537,7 @@ class PortableContact
                        self::checkServer($server["url"], $server["network"], true);
 
                        // If we couldn't reach the server, we will try it some time later
-                       $fields = ['last_poco_query' => datetime_convert()];
+                       $fields = ['last_poco_query' => DateTimeFormat::utcNow()];
                        dba::update('gserver', $fields, ['nurl' => $server["nurl"]]);
 
                        return false;
@@ -1560,7 +1563,7 @@ class PortableContact
                        foreach ($r as $server) {
                                if (!self::checkServer($server["url"], $server["network"])) {
                                        // The server is not reachable? Okay, then we will try it later
-                                       $fields = ['last_poco_query' => datetime_convert()];
+                                       $fields = ['last_poco_query' => DateTimeFormat::utcNow()];
                                        dba::update('gserver', $fields, ['nurl' => $server["nurl"]]);
                                        continue;
                                }
@@ -1653,7 +1656,7 @@ class PortableContact
                        }
 
                        if (isset($entry->updated)) {
-                               $updated = date("Y-m-d H:i:s", strtotime($entry->updated));
+                               $updated = date(DateTimeFormat::MYSQL, strtotime($entry->updated));
                        }
 
                        if (isset($entry->network)) {