- /**
- * @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 function updateContactAvatar($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 = $this->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)) {
- $this->updateContactAvatar($avatar, 0, $pcontact['id'], $force);
- }
- }
-
- return $photos;
- }
- }
-
- return $data;
- }
-