X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FUser.php;h=71e2c8a81200d2942ad64f62dd642a4146688e6f;hb=8dc0ab9bb3379fec0be442160db1ae29ef8cea9d;hp=e27a950adb57f609039f93e7ad5b5ff85f16d446;hpb=e1bd8fdba09f213373e8ecb9e1a30a408bdef82d;p=friendica.git diff --git a/src/Model/User.php b/src/Model/User.php index e27a950adb..71e2c8a812 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -1,6 +1,6 @@ $uid]); if (DBA::isResult($user)) { @@ -499,26 +500,6 @@ class User return $default_group; } - - /** - * Authenticate a user with a clear text password - * - * @param mixed $user_info - * @param string $password - * @param bool $third_party - * @return int|boolean - * @deprecated since version 3.6 - * @see User::getIdFromPasswordAuthentication() - */ - public static function authenticate($user_info, $password, $third_party = false) - { - try { - return self::getIdFromPasswordAuthentication($user_info, $password, $third_party); - } catch (Exception $ex) { - return false; - } - } - /** * Authenticate a user with a clear text password * @@ -706,7 +687,7 @@ class User { $cache = new CacheItemPool(); $cache->changeConfig([ - 'cacheDirectory' => get_temppath() . '/password-exposed-cache/', + 'cacheDirectory' => System::getTempPath() . '/password-exposed-cache/', ]); try { @@ -871,19 +852,46 @@ class User break; } - $updated = ''; - $imagetype = IMAGETYPE_JPEG; + $updated = ''; + $mimetype = ''; $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']); + $updated = max($photo['created'], $photo['edited'], $photo['updated']); + $mimetype = $photo['type']; + } - if (in_array($photo['type'], ['image/png', 'image/gif'])) { - $imagetype = IMAGETYPE_PNG; - } + return $url . $user['nickname'] . Images::getExtensionByMimeType($mimetype) . ($updated ? '?ts=' . strtotime($updated) : ''); + } + + /** + * Get banner link for given user + * + * @param array $user + * @return string banner link + * @throws Exception + */ + public static function getBannerUrl(array $user):string + { + if (empty($user['nickname'])) { + DI::logger()->warning('Missing user nickname key', ['trace' => System::callstack(20)]); + } + + $url = DI::baseUrl() . '/photo/banner/'; + + $updated = ''; + $mimetype = ''; + + $photo = Photo::selectFirst(['type', 'created', 'edited', 'updated'], ["scale" => 3, 'uid' => $user['uid'], 'photo-type' => Photo::USER_BANNER]); + if (!empty($photo)) { + $updated = max($photo['created'], $photo['edited'], $photo['updated']); + $mimetype = $photo['type']; + } else { + // Only for the RC phase: Don't return an image link for the default picture + return ''; } - return $url . $user['nickname'] . image_type_to_extension($imagetype) . ($updated ? '?ts=' . strtotime($updated) : ''); + return $url . $user['nickname'] . Images::getExtensionByMimeType($mimetype) . ($updated ? '?ts=' . strtotime($updated) : ''); } /** @@ -911,18 +919,18 @@ class User $using_invites = DI::config()->get('system', 'invitation_only'); - $invite_id = !empty($data['invite_id']) ? Strings::escapeTags(trim($data['invite_id'])) : ''; - $username = !empty($data['username']) ? Strings::escapeTags(trim($data['username'])) : ''; - $nickname = !empty($data['nickname']) ? Strings::escapeTags(trim($data['nickname'])) : ''; - $email = !empty($data['email']) ? Strings::escapeTags(trim($data['email'])) : ''; - $openid_url = !empty($data['openid_url']) ? Strings::escapeTags(trim($data['openid_url'])) : ''; - $photo = !empty($data['photo']) ? Strings::escapeTags(trim($data['photo'])) : ''; - $password = !empty($data['password']) ? trim($data['password']) : ''; - $password1 = !empty($data['password1']) ? trim($data['password1']) : ''; - $confirm = !empty($data['confirm']) ? trim($data['confirm']) : ''; + $invite_id = !empty($data['invite_id']) ? trim($data['invite_id']) : ''; + $username = !empty($data['username']) ? trim($data['username']) : ''; + $nickname = !empty($data['nickname']) ? trim($data['nickname']) : ''; + $email = !empty($data['email']) ? trim($data['email']) : ''; + $openid_url = !empty($data['openid_url']) ? trim($data['openid_url']) : ''; + $photo = !empty($data['photo']) ? trim($data['photo']) : ''; + $password = !empty($data['password']) ? trim($data['password']) : ''; + $password1 = !empty($data['password1']) ? trim($data['password1']) : ''; + $confirm = !empty($data['confirm']) ? trim($data['confirm']) : ''; $blocked = !empty($data['blocked']); $verified = !empty($data['verified']); - $language = !empty($data['language']) ? Strings::escapeTags(trim($data['language'])) : 'en'; + $language = !empty($data['language']) ? trim($data['language']) : 'en'; $netpublish = $publish = !empty($data['profile_publish_reg']); @@ -979,7 +987,7 @@ class User $username_max_length = max(1, min(64, intval(DI::config()->get('system', 'username_max_length', 48)))); if ($username_min_length > $username_max_length) { - Logger::log(DI::l10n()->t('system.username_min_length (%s) and system.username_max_length (%s) are excluding each other, swapping values.', $username_min_length, $username_max_length), Logger::WARNING); + Logger::error(DI::l10n()->t('system.username_min_length (%s) and system.username_max_length (%s) are excluding each other, swapping values.', $username_min_length, $username_max_length)); $tmp = $username_min_length; $username_min_length = $username_max_length; $username_max_length = $tmp; @@ -1144,8 +1152,9 @@ class User $photo_failure = false; $filename = basename($photo); - $curlResult = DI::httpClient()->get($photo); + $curlResult = DI::httpClient()->get($photo, HttpClientAccept::IMAGE); if ($curlResult->isSuccess()) { + Logger::debug('Got picture', ['Content-Type' => $curlResult->getHeader('Content-Type'), 'url' => $photo]); $img_str = $curlResult->getBody(); $type = $curlResult->getContentType(); } else { @@ -1161,7 +1170,10 @@ class User $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; @@ -1169,7 +1181,7 @@ class User $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; @@ -1177,14 +1189,14 @@ class User $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]); } } @@ -1276,7 +1288,7 @@ class User $profile = DBA::selectFirst('profile', ['net-publish'], ['uid' => $register['uid']]); - if (DBA::isResult($profile) && $profile['net-publish'] && DI::config()->get('system', 'directory')) { + if (DBA::isResult($profile) && $profile['net-publish'] && Search::getGlobalDirectory()) { $url = DI::baseUrl() . '/profile/' . $user['nickname']; Worker::add(PRIORITY_LOW, "Directory", $url); } @@ -1514,7 +1526,7 @@ class User return false; } - Logger::log('Removing user: ' . $uid); + Logger::notice('Removing user', ['user' => $uid]); $user = DBA::selectFirst('user', [], ['uid' => $uid]);