use Friendica\Util\DateTimeFormat;
use Friendica\Util\Images;
use Friendica\Util\Network;
+use Friendica\Util\Proxy;
use Friendica\Util\Strings;
/**
if (empty($cid)) {
return [];
}
- return self::getById($cid, $fields);
+
+ $contact = self::getById($cid, $fields);
+ if (empty($contact)) {
+ return [];
+ }
+ return $contact;
}
// Add internal fields
$contact = DBA::selectFirst('contact', $fields, $condition, $options);
}
+ if (!DBA::isResult($contact)) {
+ return [];
+ }
+
// Update the contact in the background if needed
if ((($contact['updated'] < DateTimeFormat::utc('now -7 days')) || empty($contact['avatar'])) &&
in_array($contact['network'], Protocol::FEDERATED)) {
self::updateAvatar($cid, $contact['avatar'], true);
}
+ /**
+ * Return the photo path for a given contact array in the given size
+ *
+ * @param array $contact contact array
+ * @param string $field Fieldname of the photo in the contact array
+ * @param string $default Default path when no picture had been found
+ * @param string $size Size of the avatar picture
+ * @param string $avatar Avatar path that is displayed when no photo had been found
+ * @return string photo path
+ */
+ private static function getAvatarPath(array $contact, string $field, string $default, string $size, string $avatar)
+ {
+ if (!empty($contact)) {
+ $contact = self::checkAvatarCacheByArray($contact);
+ if (!empty($contact[$field])) {
+ $avatar = $contact[$field];
+ }
+ }
+
+ if (empty($avatar)) {
+ return $default;
+ }
+
+ if (Proxy::isLocalImage($avatar)) {
+ return $avatar;
+ } else {
+ return Proxy::proxifyUrl($avatar, false, $size);
+ }
+ }
+
+ /**
+ * Return the photo path for a given contact array
+ *
+ * @param array $contact Contact array
+ * @param string $avatar Avatar path that is displayed when no photo had been found
+ * @return string photo path
+ */
+ public static function getPhoto(array $contact, string $avatar = '')
+ {
+ return self::getAvatarPath($contact, 'photo', DI::baseUrl() . '/images/person-300.jpg', Proxy::SIZE_SMALL, $avatar);
+ }
+
+ /**
+ * Return the photo path (thumb size) for a given contact array
+ *
+ * @param array $contact Contact array
+ * @param string $avatar Avatar path that is displayed when no photo had been found
+ * @return string photo path
+ */
+ public static function getThumb(array $contact, string $avatar = '')
+ {
+ return self::getAvatarPath($contact, 'thumb', DI::baseUrl() . '/images/person-80.jpg', Proxy::SIZE_THUMB, $avatar);
+ }
+
+ /**
+ * Return the photo path (micro size) for a given contact array
+ *
+ * @param array $contact Contact array
+ * @param string $avatar Avatar path that is displayed when no photo had been found
+ * @return string photo path
+ */
+ public static function getMicro(array $contact, string $avatar = '')
+ {
+ return self::getAvatarPath($contact, 'micro', DI::baseUrl() . '/images/person-48.jpg', Proxy::SIZE_MICRO, $avatar);
+ }
+
/**
* Check the given contact array for avatar cache fields
*
* @param array $contact
* @return array contact array with avatar cache fields
*/
- public static function checkAvatarCacheArray(array $contact)
+ private static function checkAvatarCacheByArray(array $contact)
{
$update = false;
$contact_fields = [];
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
- public static function updateFromProbe($id, $network = '', $force = false)
+ public static function updateFromProbe(int $id, string $network = '', bool $force = false)
{
/*
Warning: Never ever fetch the public key via Probe::uri and write it into the contacts.
return false;
}
+ if (ContactRelation::isDiscoverable($ret['url'])) {
+ Worker::add(PRIORITY_LOW, 'ContactDiscovery', $ret['url']);
+ }
+
if (isset($ret['hide']) && is_bool($ret['hide'])) {
$ret['unsearchable'] = $ret['hide'];
}
GContact::updateFromPublicContactID($id);
}
- ContactRelation::discoverByUrl($ret['url']);
-
$update = false;
// make sure to not overwrite existing values with blank entries except some technical fields