From: Hypolite Petovan Date: Fri, 1 Dec 2017 05:48:13 +0000 (-0500) Subject: Merge branch 'develop' into task/admin-block-list X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ff459441cfd86375a7b0ed5f2d6854fbd0ae3a00;p=friendica.git Merge branch 'develop' into task/admin-block-list --- ff459441cfd86375a7b0ed5f2d6854fbd0ae3a00 diff --cc src/Object/Contact.php index 1aee2c2b57,72f287a3ef..361d8e3ac8 --- a/src/Object/Contact.php +++ b/src/Object/Contact.php @@@ -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; } }