]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Pagecache for frequently fetched pages
[friendica.git] / src / Model / Contact.php
index 12be608127a802b74ed197afda976609ac4eb74a..6a57693991127be745e836acf043a08ecec04ed9 100644 (file)
@@ -160,6 +160,7 @@ class Contact
                        $fields['created'] = DateTimeFormat::utcNow();
                }
 
+               $fields = DI::dbaDefinition()->truncateFieldsForTable('contact', $fields);
                DBA::insert('contact', $fields, $duplicate_mode);
                $contact = DBA::selectFirst('contact', [], ['id' => DBA::lastInsertId()]);
                if (!DBA::isResult($contact)) {
@@ -191,6 +192,7 @@ class Contact
         */
        public static function update(array $fields, array $condition, $old_fields = [])
        {
+               $fields = DI::dbaDefinition()->truncateFieldsForTable('contact', $fields);
                $ret = DBA::update('contact', $fields, $condition, $old_fields);
 
                // Apply changes to the "user-contact" table on dedicated fields
@@ -327,14 +329,15 @@ class Contact
        /**
         * Tests if the given contact is a follower
         *
-        * @param int $cid Either public contact id or user's contact id
-        * @param int $uid User ID
+        * @param int  $cid    Either public contact id or user's contact id
+        * @param int  $uid    User ID
+        * @param bool $strict If "true" then contact mustn't be set to pending or readonly
         *
         * @return boolean is the contact id a follower?
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function isFollower(int $cid, int $uid): bool
+       public static function isFollower(int $cid, int $uid, bool $strict = false): bool
        {
                if (Contact\User::isBlocked($cid, $uid)) {
                        return false;
@@ -346,20 +349,24 @@ class Contact
                }
 
                $condition = ['id' => $cdata['user'], 'rel' => [self::FOLLOWER, self::FRIEND]];
+               if ($strict) {
+                       $condition = array_merge($condition, ['pending' => false, 'readonly' => false, 'blocked' => false]);
+               }
                return DBA::exists('contact', $condition);
        }
 
        /**
         * Tests if the given contact url is a follower
         *
-        * @param string $url Contact URL
-        * @param int    $uid User ID
+        * @param string $url    Contact URL
+        * @param int    $uid    User ID
+        * @param bool   $strict If "true" then contact mustn't be set to pending or readonly
         *
         * @return boolean is the contact id a follower?
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function isFollowerByURL(string $url, int $uid): bool
+       public static function isFollowerByURL(string $url, int $uid, bool $strict = false): bool
        {
                $cid = self::getIdForURL($url, $uid);
 
@@ -367,20 +374,21 @@ class Contact
                        return false;
                }
 
-               return self::isFollower($cid, $uid);
+               return self::isFollower($cid, $uid, $strict);
        }
 
        /**
         * Tests if the given user shares with the given contact
         *
-        * @param int $cid Either public contact id or user's contact id
-        * @param int $uid User ID
+        * @param int  $cid    Either public contact id or user's contact id
+        * @param int  $uid    User ID
+        * @param bool $strict If "true" then contact mustn't be set to pending or readonly
         *
         * @return boolean is the contact sharing with given user?
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function isSharing(int $cid, int $uid): bool
+       public static function isSharing(int $cid, int $uid, bool $strict = false): bool
        {
                if (Contact\User::isBlocked($cid, $uid)) {
                        return false;
@@ -392,20 +400,24 @@ class Contact
                }
 
                $condition = ['id' => $cdata['user'], 'rel' => [self::SHARING, self::FRIEND]];
+               if ($strict) {
+                       $condition = array_merge($condition, ['pending' => false, 'readonly' => false, 'blocked' => false]);
+               }
                return DBA::exists('contact', $condition);
        }
 
        /**
         * Tests if the given user follow the given contact url
         *
-        * @param string $url Contact URL
-        * @param int    $uid User ID
+        * @param string $url    Contact URL
+        * @param int    $uid    User ID
+        * @param bool   $strict If "true" then contact mustn't be set to pending or readonly
         *
         * @return boolean is the contact url being followed?
         * @throws HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
-       public static function isSharingByURL(string $url, int $uid): bool
+       public static function isSharingByURL(string $url, int $uid, bool $strict = false): bool
        {
                $cid = self::getIdForURL($url, $uid);
 
@@ -413,7 +425,7 @@ class Contact
                        return false;
                }
 
-               return self::isSharing($cid, $uid);
+               return self::isSharing($cid, $uid, $strict);
        }
 
        /**
@@ -1287,7 +1299,7 @@ class Contact
                        }
 
                        if (!$contact_id) {
-                               Logger::info('Contact was not inserted', ['url' => $url, 'uid' => $uid]);
+                               Logger::warning('Contact was not inserted', ['url' => $url, 'uid' => $uid]);
                                return 0;
                        }
                } else {
@@ -3309,7 +3321,7 @@ class Contact
                                continue;
                        }
                        $contact = self::getByURL($url, false, ['id', 'updated']);
-                       if (empty($contact['id'])) {
+                       if (empty($contact['id']) && Network::isValidHttpUrl($url)) {
                                Worker::add(PRIORITY_LOW, 'AddContact', 0, $url);
                                ++$added;
                        } elseif ($contact['updated'] < DateTimeFormat::utc('now -7 days')) {