$system['closeness'] = 0;
$system['baseurl'] = DI::baseUrl();
$system['gsid'] = GServer::getID($system['baseurl']);
- DBA::insert('contact', $system);
+ Contact::insert($system);
}
/**
}
/**
- * Get avatar link for given user id
+ * Get avatar link for given user
*
- * @param integer $uid user id
- * @param string $size One of the ProxyUtils::SIZE_* constants
+ * @param array $user
+ * @param string $size One of the Proxy::SIZE_* constants
* @return string avatar link
+ * @throws Exception
*/
- public static function getAvatarUrlForId(int $uid, string $size = ''):string
+ public static function getAvatarUrl(array $user, string $size = ''):string
{
+ if (empty($user['nickname'])) {
+ DI::logger()->warning('Missing user nickname key', ['trace' => System::callstack(20)]);
+ }
+
$url = DI::baseUrl() . '/photo/';
switch ($size) {
$updated = '';
$imagetype = IMAGETYPE_JPEG;
- $photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => $scale, 'uid' => $uid, 'profile' => true]);
+ $photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => $scale, 'uid' => $user['uid'], 'profile' => true]);
if (!empty($photo)) {
$updated = max($photo['created'], $photo['edited'], $photo['updated']);
- switch ($photo['type']) {
- case 'image/png':
- $imagetype = IMAGETYPE_PNG;
- break;
-
- case 'image/gif':
- $imagetype = IMAGETYPE_PNG;
- break;
-
- default:
- $imagetype = IMAGETYPE_JPEG;
- break;
+ if (in_array($photo['type'], ['image/png', 'image/gif'])) {
+ $imagetype = IMAGETYPE_PNG;
}
}
- return $url . $uid . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
+ return $url . $user['nickname'] . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : '');
}
/**
$insert_result = DBA::insert('profile', [
'uid' => $uid,
'name' => $username,
- 'photo' => self::getAvatarUrlForId($uid),
- 'thumb' => self::getAvatarUrlForId($uid, Proxy::SIZE_THUMB),
+ 'photo' => self::getAvatarUrl($user),
+ 'thumb' => self::getAvatarUrl($user, Proxy::SIZE_THUMB),
'publish' => $publish,
'net-publish' => $netpublish,
]);
$resource_id = Photo::newResource();
- $r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 4);
+ // Not using Photo::PROFILE_PHOTOS here, so that it is discovered as translateble string
+ $profile_album = DI::l10n()->t('Profile Photos');
+
+ $r = Photo::store($Image, $uid, 0, $resource_id, $filename, $profile_album, 4);
if ($r === false) {
$photo_failure = true;
$Image->scaleDown(80);
- $r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 5);
+ $r = Photo::store($Image, $uid, 0, $resource_id, $filename, $profile_album, 5);
if ($r === false) {
$photo_failure = true;
$Image->scaleDown(48);
- $r = Photo::store($Image, $uid, 0, $resource_id, $filename, DI::l10n()->t('Profile Photos'), 6);
+ $r = Photo::store($Image, $uid, 0, $resource_id, $filename, $profile_album, 6);
if ($r === false) {
$photo_failure = true;
}
if (!$photo_failure) {
- Photo::update(['profile' => 1], ['resource-id' => $resource_id]);
+ Photo::update(['profile' => true, 'photo-type' => Photo::USER_AVATAR], ['resource-id' => $resource_id]);
}
}