]> git.mxchange.org Git - friendica.git/commitdiff
Merge branch 'develop' into task/admin-block-list
authorHypolite Petovan <mrpetovan@gmail.com>
Fri, 1 Dec 2017 05:48:13 +0000 (00:48 -0500)
committerGitHub <noreply@github.com>
Fri, 1 Dec 2017 05:48:13 +0000 (00:48 -0500)
1  2 
src/Object/Contact.php

index 1aee2c2b57fcc18092e82a69124ad0b71cb16a75,72f287a3ef04ea35187e5d87a0d085ff22c01ea3..361d8e3ac863880f199dd2e0c51d2eabd86fba8a
@@@ -823,28 -822,47 +822,73 @@@ class Contact extends BaseObjec
        }
  
        /**
 -       * @brief Updates the avatar links in a contact only if needed
 +       * @brief Blocks a contact
 +       *
 +       * @param int $uid
 +       * @return bool
 +       */
 +      public static function block($uid)
 +      {
 +              $return = dba::update('contact', ['blocked' => true], ['id' => $uid]);
 +
 +              return $return;
 +      }
 +
 +      /**
 +       * @brief Unblocks a contact
 +       *
 +       * @param int $uid
 +       * @return bool
 +       */
 +      public static function unblock($uid)
 +      {
 +              $return = dba::update('contact', ['blocked' => false], ['id' => $uid]);
 +
 +              return $return;
++  }
++
++  /**
++   * @brief Updates the avatar links in a contact only if needed
+        *
+        * @param string $avatar Link to avatar picture
+        * @param int    $uid    User id of contact owner
+        * @param int    $cid    Contact id
+        * @param bool   $force  force picture update
+        *
+        * @return array Returns array of the different avatar sizes
+        */
+       public static function updateAvatar($avatar, $uid, $cid, $force = false)
+       {
+               // Limit = 1 returns the row so no need for dba:inArray()
+               $r = dba::select('contact', array('avatar', 'photo', 'thumb', 'micro', 'nurl'), array('id' => $cid), array('limit' => 1));
+               if (!DBM::is_result($r)) {
+                       return false;
+               } else {
+                       $data = array($r["photo"], $r["thumb"], $r["micro"]);
+               }
+               if (($r["avatar"] != $avatar) || $force) {
+                       $photos = Photo::importProfilePhoto($avatar, $uid, $cid, true);
+                       if ($photos) {
+                               dba::update(
+                                       'contact',
+                                       array('avatar' => $avatar, 'photo' => $photos[0], 'thumb' => $photos[1], 'micro' => $photos[2], 'avatar-date' => datetime_convert()),
+                                       array('id' => $cid)
+                               );
+                               // Update the public contact (contact id = 0)
+                               if ($uid != 0) {
+                                       $pcontact = dba::select('contact', array('id'), array('nurl' => $r[0]['nurl']), array('limit' => 1));
+                                       if (DBM::is_result($pcontact)) {
+                                               self::updateAvatar($avatar, 0, $pcontact['id'], $force);
+                                       }
+                               }
+                               return $photos;
+                       }
+               }
+               return $data;
        }
  }