- if (!empty($parameters['customsize'])) {
- $customsize = intval($parameters['customsize']);
- $uid = MPhoto::stripExtension($parameters['name']);
- $photo = self::getAvatar($uid, $parameters['type'], $customsize);
- $square_resize = !in_array($parameters['type'], ['media', 'preview']);
- } elseif (!empty($parameters['type'])) {
- $uid = MPhoto::stripExtension($parameters['name']);
- $photo = self::getAvatar($uid, $parameters['type'], Proxy::PIXEL_SMALL);
- } elseif (!empty($parameters['name'])) {
- $photoid = MPhoto::stripExtension($parameters['name']);
+ // User avatar
+ if (!empty($this->parameters['type'])) {
+ if (!empty($this->parameters['customsize'])) {
+ $customsize = intval($this->parameters['customsize']);
+ $square_resize = !in_array($this->parameters['type'], ['media', 'preview']);
+ }
+
+ if (!empty($this->parameters['guid'])) {
+ $guid = $this->parameters['guid'];
+ $account = DBA::selectFirst('account-user-view', ['id'], ['guid' => $guid], ['order' => ['uid' => true]]);
+ if (empty($account)) {
+ throw new HTTPException\NotFoundException();
+ }
+
+ $id = $account['id'];
+ }
+
+ // Contact Id Fallback, to remove after version 2021.12
+ if (isset($this->parameters['contact_id'])) {
+ $id = intval($this->parameters['contact_id']);
+ }
+
+ if (!empty($this->parameters['nickname_ext'])) {
+ $nickname = pathinfo($this->parameters['nickname_ext'], PATHINFO_FILENAME);
+ $user = User::getByNickname($nickname, ['uid']);
+ if (empty($user)) {
+ throw new HTTPException\NotFoundException();
+ }
+
+ $id = $user['uid'];
+ }
+
+ // User Id Fallback, to remove after version 2021.12
+ if (!empty($this->parameters['uid_ext'])) {
+ $id = intval(pathinfo($this->parameters['uid_ext'], PATHINFO_FILENAME));
+ }
+
+ // Please refactor this for the love of everything that's good
+ if (isset($this->parameters['id'])) {
+ $id = $this->parameters['id'];
+ }
+
+ if (empty($id)) {
+ Logger::notice('No picture id was detected', ['parameters' => $this->parameters, 'query' => DI::args()->getQueryString()]);
+ throw new HTTPException\NotFoundException(DI::l10n()->t('The Photo is not available.'));
+ }
+
+ $photo = self::getPhotoByid($id, $this->parameters['type'], $customsize ?: Proxy::PIXEL_SMALL);
+ } else {
+ $photoid = pathinfo($this->parameters['name'], PATHINFO_FILENAME);