}
/**
- * @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;
}
}